I have an UIButton array like this:
@property (nonatomic, retain) IBOutletCollection(UIButton) NSArray *btn_Impact_Collection;
and I have this function:
- (IBAction)impactAction:(id)sender;
In the XIB file I have nine button, each button is connected to btn_Impact_Collection Array with the Referencing Outlet Collection. Moreover the Touch_inside property of each button is connected to the function ImpactAction.
Now, when a button is clicked the ImpactAction function is called, but inside this function, how can i know which button is pressed?
Thanks in advance for the answer!
Cast sender to UIButton class, and that will give you the instance of the clicked button. I don't have Xcode with me but something like:
Set tags for each button in interface builder (1-9), then say
And the same for all the others, or you could put it in a switch.
Another option.. Cast sender to check if it's a UIButton, then switch sender.tag:
Rather than do a string check on the title (which is slow and can be tedious) you can: