Search code examples
iphoneuinavigationcontrollerpushviewcontroller

pushViewController crahses


I'm trying to push a new view on my navigation controller using:

    -(IBAction)switchPage:(id)sender
{
 MyTableViewController *myTableView = [[CMyTableViewController alloc] initWithNibName:@"MyTableView" bundle:[NSBundle mainBundle]];
 [myTableView release];
 [self.navigationController pushViewController:myTableView animated:YES];
}

I'm running into the following error:

2010-02-25 21:19:57.717 CoC[3399:20b] *** -[UIViewController switchPage:]: unrecognized selector sent to instance 0xf1a660
2010-02-25 21:19:57.718 CoC[3399:20b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[UIViewController switchPage:]: unrecognized selector sent to instance 0xf1a660'

Solution

  • you are releasing an object you just allocated which makes no sense.

     MyTableViewController *myTableView = [[CMyTableViewController alloc] initWithNibName:@"MyTableView" bundle:[NSBundle mainBundle]];
         [myTableView release];
    

    release myTableView after you push it onto the stack