简体   繁体   中英

Perform segue from unbutton results in “unrecognized selector” error

I have implemented a simple segue from a button click. Here is the view controller code:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
   {
{
    if (self.categoryInt == 1)
        [segue.destinationViewController setCategoryKey:SD_ADDITION];
    else if (self.categoryInt == 2)
       [segue.destinationViewController setCategoryKey:SD_SUBTRACTION];

}}

- (IBAction)category1Selected:(id)sender {
self.categoryInt = 1;
[self performSegueWithIdentifier:@"ShowWorksheet" sender:self];}

From the log messages, I can see that it ran through the ViewDidLoad on the destinationviewcontroller completely but then it errors out with: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MainMenuViewController categorySelected:]: unrecognized selector sent to instance 0x75360e0'

I have not implemented any specific selectors on these buttons. Also there is no "categorySelected" method in my MainMenuViewController. The method being invoked is "category1Selected". What is causing this error?

I think you answered the question yourself. You are somehow sending "categorySelected" when you SHOULD be sending category1Selected.

Check to see if you previously wired a button to categorySelected in interface builder. If you had previously done this, but then changed the name of categorySelected to category1Selected in your code, interface builder would probably not update.

This is usually a connection error, go to your connections inspector and make sure all is correct there.

If your not sure disconnect all the connections and re make the connections double checking everything.

Also Make sure you haven't connected the action button as an outlet in addition to its action command.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM