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?
When using Push Segues you can easily go back to the root using this method:
When using Modal Segues (because of the word dismiss in the question and as a general reference) you can
dismiss
the view controller using this method:The
UINavigationController
has a stack ofViewControllers
which is stored in the viewControllers(NSArray) property. Enumerate to the requiredViewController
and pop to thatViewController
.Following code should solve the problem.
Swift:
Objective-C:
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.
I had this problem recently and solved with something like this...
If you are using Storyboads, use this segue: