Choose correct UIButton on dynamiclly created buttons without tags
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 press开发者_如何学编程ed 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!
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.
精彩评论