tags:

views:

22

answers:

1

I am loading up a plist file and creating buttons based on this file. These buttons can change at any point during the application running (which will trigger an update of all the buttons etc).

One set of buttons represents a list of categories. So I may have a house button, car button, etc. No matter what button is pressed it will call my categoryButtonPressed:(id) sender function. I need to know what button called it and load a second set of data based on the button (category) that was pressed.

So if I press the house button, the function needs to load the house data, but how can I determine what button was pressed in that function. If I use tags I have to know that the house button is tag 1, car is tag 2 and so forth. BUT I don't know if there will even be a house button until I read that file. Do I need to code the tag into the plist file as well?

OR is there a way to loop through my Array of UIButtons and determine this? Any advice?

And last, if I create my own extended version of UIButton that added a "name" variable, would I would still be out of luck because the action would pass the UIButton base and comparing my extended class to the base would always fail correct?

Thanks for any and all help!

A: 

And last, if I create my own extended version of UIButton that added a "name" variable, would I would still be out of luck because the action would pass the UIButton base and comparing my extended class to the base would always fail correct?

The action is passed by whatever control, of whatever class, the action was registered with. Creating your own custom button with additional properties seems like the way to go.

You could also set the tag of the button as the index in your button array, or the index in the plist that the button corresponds to.

drawnonward
If I do create a custom button and use that how would I compare those two objects for equality? I'm sorta still new to Objective-C. Do I just use the == or is there a Class Equals modifier?
David Nelson
There is an 'isEqual:` method, but unless you implement it for your custom class it falls back on pointer equality. Pointer equality is sufficient unless different instances of the class may be equivalent.
drawnonward