user2534010
user2534010

Reputation: 51

setText in objective C causes a runtime crash

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

Answers (1)

Paul Lynch
Paul Lynch

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

Related Questions