PDA

View Full Version : NOOB Question: How to pass a text parameter on click of button




oceandrive
Dec 10, 2008, 12:33 PM
Case:

I have 9 different buttons (Can grow) with images on them. I want to have a single method to handle the action for all. Is there a way for me to know which button is pressed.

The Button Tag does not work for me because it taken only Integers and in my case I want to pass a text (Ex: Multiple, divide, add, sub, doubleAdd).

I will not have any title on my buttons, just image buttons.

Thanks for the help.



dejo
Dec 10, 2008, 12:40 PM
The Button Tag does not work for me because it taken only Integers and in my case I want to pass a text (Ex: Multiple, divide, add, sub, doubleAdd).
Do a mapping between the integers and the text. I.E. Multiply = 0, Divide = 1, Add = 2. Then set up an array of the text values and you can just retrieve them using objectAtIndex (where the index is your tag integer). Make sense?

oceandrive
Dec 10, 2008, 12:58 PM
Yes sir....

Is there a way to set the font size for the title of the button to zero and use the [botton currentTitle]; ?

dejo
Dec 10, 2008, 01:12 PM
Is there a way to set the font size for the title of the button to zero and use the [botton currentTitle]; ?
No need to set the font size to zero. The image overrides the display of the title. So you can do:
[button setTitle:@"title" forState:UIControlStateNormal]
[button setImage:buttonImage forState:UIControlStateNormal]

and then later just retrieve the title with:
[button currentTitle]

oceandrive
Dec 10, 2008, 01:19 PM
But in my interface builder when I select the Normal state and set the title and then select the image for my button, both the button and the image show up. Am I missing ?

dejo
Dec 10, 2008, 02:08 PM
But in my interface builder when I select the Normal state and set the title and then select the image for my button, both the button and the image show up. Am I missing ?
Ah, I see what you mean. I had just tried it through the code. I don't think you can resize the font for the button in Interface Builder, so you're gonna have to use the code for whatever solution you decide to go with. I'd suggest not using the title, if you're not really intending on showing it anyways. Tags and a text-lookup-array would be my suggestion.

oceandrive
Dec 10, 2008, 02:33 PM
ok I will use the tags and text lookup as u suggested. Thanks for the guidance.

PhoneyDeveloper
Dec 11, 2008, 10:38 AM
You can set the font for a button in IB with the Font menu. Select the button and choose any item from the Font menu to change the font properties.

oceandrive
Dec 11, 2008, 03:24 PM
does not allow a zero font size.

dejo
Dec 11, 2008, 03:34 PM
More hints on how to do something like this in this posting: http://forums.macrumors.com/showpost.php?p=6745956&postcount=4