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?
The
-popToViewController
is used to pop view controllers OFF the stack, down to one that already exists. YourUINavigationController
has a stack of ViewControllers (stored in theviewControllers
property), when youpopToViewController
, 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 topViewController
from the stackI resolved this by using
pushViewController
rather thanpopToViewController