yesimarobot
yesimarobot

Reputation: 283

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'

Upvotes: 0

Views: 1986

Answers (6)

BluePenguin
BluePenguin

Reputation: 11

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.

Upvotes: 1

Manjunath
Manjunath

Reputation: 4555

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

Upvotes: 1

jkeesh
jkeesh

Reputation: 3339

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];
}

Upvotes: 0

ennuikiller
ennuikiller

Reputation: 46985

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

Upvotes: 1

sha
sha

Reputation: 17860

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

Upvotes: 0

pm_labs
pm_labs

Reputation: 1145

Call release after pushing.

Upvotes: 2

Related Questions