, setSelected: YES , . :
- (void) methodThatYourButtonCalls: (id) sender {
[self performSelector:@selector(flipButton:) withObject:sender afterDelay:0.0];
}
- (void) flipButton:(UIButton*) button {
if(button.selected)
[button setSelected:NO];
else
[button setSelected:YES];
}
, performSelector: , [sender setSelected: YES], , !
To force the buttons to deselect when another button is pressed, I suggest adding an instance variable containing a pointer to the currently selected button, so when the new one touches, you can call flipButton: deselect the old one accordingly. So now your code should read:
add a pointer to your interface
@interface YourViewController : UIViewController
{
UIButton *currentlySelectedButton;
}
and these methods for your implementation
- (void) methodThatYourButtonCalls: (id) sender {
UIButton *touchedButton = (UIButton*) sender;
[self performSelector:@selector(flipButton:) withObject:sender afterDelay:0.0];
if(currentlySelectedButton != nil) {
[self flipButton:currentlySelectedButton];
currentlySelectedButton = touchedButton;
}
- (void) flipButton:(UIButton*) button {
if(button.selected)
[button setSelected:NO];
else
[button setSelected:YES];
}
source
share