I'm new to iPhone dev. My app is dynamically creating buttons, following from my data model. The model isn't just a simple list; it's a tree. I need some way to correlate a created button to that data model, so that when the button is clicked I know what part of the model it corresponds to.
On Windows, most UI controls have a "tag" field where you could put custom data. Using a similar pattern, what I'd like to do on the iPhone is this:
- (void)createMyButton:(MyModel*)foo
{
UIButton* button = <insert creation code here>
[button addTarget:self action:@selector(handleCreatedButtonTouch:) ...];
button.tag = foo;
}
- (void)handleCreatedButtonTouch:(id)sender
{
UIButton* button = (UIButton*)sender;
MyModel* foo = (MyModel*)(button.tag);
[foo userTouchedMyButton];
}
I can't find any mention of such a field in the Apple documentation. How do you iPhone gurus do this? Again, I don't have any simple way of indexing into my data model, and doing an enumeration over the entire data model to find a match seems very wrong.