views:

256

answers:

2

I am getting this error when I call my method dismissView. Here is the method stub:

-(IBAction)dismissView
{
    RootViewController *rootController = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil];
    [self.navigationController popToViewController:rootController animated:YES];
}

That should work, and I've checked, rootController is initialized and allocated. Any ideas?

+2  A: 

The -popToViewController is used to pop view controllers OFF the stack, down to one that already exists. Your NavigationController has a stack of ViewControllers (stored in the viewControllers property), when you popToViewController, you're going to want to pass one of the elements in that array as the first argument.

What you most likely want to do in this case is use -popViewControllerAnimated:, which will remove the top ViewController from the stack

Ben Gottlieb
A: 

You're allocating the RootViewController right there. It does not exist in the navigation controller's stack, so no matter how far you pop, you won't reach it.

Chuck