Search code examples
iphonedynamicuibuttoncreation

UIButton : managing dynamic creation and touch events


I'm currently dynamically creating UIButton objects in my view.

I have an NSMutableArray containing information about them (id - label).

I then create my view objects by doing a for iteration on my MutableArray.

I'm trying to use this code on my buttons to catch touche events :

[myButton addTarget:self action:@selector(selectedButton:) forControlEvents:UIControlEventTouchUpInside];

My selectedButton method is called with success, but I don't have any idea on knowing with button were touched.

I tried to do this :

-(void)selectedButton:(id)sender {...}

But don't know what to do with the sender object.

Thanks in advance for your help !


Solution

  • Set mybutton.tag to something, and then check for that tag in selectedButton:sender.