Question

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'
Was it helpful?

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

OTHER TIPS

Call release after pushing.

2010-02-25 21:19:57.717 CoC[3399:20b] * ** -[UIViewController switchPage:]: unrecognized selector sent to instance 0xf1a660

Your crash not because of the code what you have mentioned. But there is a bug in you code like release and thenpush. Change it as:

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

I guess the object which is calling "switchPage:" method is having some problem. Check it or show the invocation of this method for any help

Regards, Manjunath

Above is alright,when the subview controller has been pushed into the nav's stack,the retain count should be increased,then you should release it after the push operation.

Are you sure you don't need to swap last two lines? First push controller, then release it not visa versa... :)

As mentioned earlier, you release the view controller before you push it. When you push it onto the navigation controller, the retain count is increased, and then you can release it.

-(IBAction)switchPage:(id)sender
{
     MyTableViewController *myTableView = [[MyTableViewController alloc] initWithNibName:@"MyTableView" bundle:[NSBundle mainBundle]];
    [self.navigationController pushViewController:myTableView animated:YES];
    [myTableView release];
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top