If you need to manipulate user interface objects like buttons, create IBOutlet properties in the view controller that manages the objects and link the objects to those properties. That done, you'll be able to use the properties to enable the button(s) like this:
-(void) reset {
//re-enable all buttons
self.buttonA.enabled = YES;
self.buttonB.enabled = YES;
//...and so on
}
If you don't want to use outlets for some reason (e.g. you have a large number of buttons and don't often need a reference to each individual button), you might also consider using tags. Every view has an integer tag
property which you can set to any value you like. Tags can be set in the .xib/storyboard editor. Once you've set a view's tag, you can easily find it in your view hierarchy using the -viewWithTag:
method. If you use tags, your -reset
method would look something like:
-(void) reset {
//re-enable all buttons
[[self.view viewWithTag:kTagForButtonA] setEnabled:YES];
[[self.view viewWithTag:kTagForButtonB] setEnabled:YES];
//...and so on
}
where kTagForButtonA
and kTagForButtonB
are integer constants that match the tags set on individual buttons. If you have lots of buttons with consecutive tags, you could obviously also use a for
loop to set each one in turn.
Also, it looks like all your actions do exactly the same thing -- each one disables the button that sent the message. If that's the case, you can use a single action for all your buttons:
- (IBAction)buttonAction:(UIButton *)sender {
sender.enabled = NO;
}