Reputation: 51
ERROR:Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView setTitle:forState:]: unrecognized selector sent to instance 0x9688830'
Tags 1-8 really exist and are correctly assigned using IB. This action has been
associated with a "restart" button using the IB.
- (IBAction)restart: (UIButton *) sender
{
NSLog(@"restart");
[board restart];
NSString *buttonText = @"";
for(int i=0;i<9;i++)
{
UIButton *button = (UIButton *)[self.view viewWithTag:i];
[button setEnabled:YES];
NSLog(@"yourObject is a: %i", className);
// THIS CAUSES A RUNTIME ERROR:
//[button setTitle:buttonText forState:UIControlStateNormal];
}
}
Upvotes: 1
Views: 116
Reputation: 19789
You are sending a UIButton
method call to a plain UIView
; most probably the untagged main view for your view controller - which will have a tag of 0.
Note that your for loop starts at 0.
Upvotes: 3