I have a uiviewcontroller with many UIButtons that are meant to be selected and kept pressed until touched on again. I define each button in the viewDidLoad and give all of them the same selector method (tapButton):
[button1 addTarget:self action:@selector(tapButton:) forControlEvents:UIControlEventTouchUpInside];
[button2 addTarget:self action:@selector(tapButton:) forControlEvents:UIControlEventTouchUpInside];
...
What I would like to do, is in the tabButton: method, to use the selector to determine which button was pressed, and then change its state with the following:
- (IBAction) tapButton:(id)sender
{
if ( sender.selected ) {
sender.highlighted = NO;
sender.selected = NO;
} else {
sender.highlighted = YES;
sender.selected = YES;
}
}
You will notice that this is merely a pseuodo code since I can’t really do “sender.selected” or “sender.highlighted” but thats what I am trying to accomplish.
is there any in way in which I can accomplish this? I would hate to create 30 “tapButton” methods (thats the number of UIButtons I have, yes…) for managing each UIButton’s state.
Thanks a bunch!
You can set the
tagof each button like thisThen in your selector