views:

365

answers:

6

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'
+2  A: 

Call release after pushing.

paul_sns
For brevity, you can also change bundle:[NSBundle mainBundle] to bundle:nil since setting it to nil defaults to using the main bundle.
paul_sns
I'm not very familiar with switchPage (which is the error being reported in your logs), are you calling that method somewhere and forgot to declare that in your ViewController perhaps?
paul_sns
A: 

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

sha
+1  A: 

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

ennuikiller
I've removed the [myTableView release] and the same error occurs.
yesimarobot
Can anyone suggest a good programmatic/non-IB UINavigationController tutorial?
yesimarobot
Can you try adding breakpoints and see if your navigationController is not null? Are you using a subclass of UITableViewController for MyTableViewController?
paul_sns
A: 

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];
}
jkeesh
+1  A: 

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

Manjunath