问题
I'm trying to pop to a specific view controller that is in the navigation stack but I am doing something wrong as I am getting this error pop up when I try to execute the code
Assertion failure in -[UINavigationController popToViewController:transition:], /SourceCache/UIKit_Sim/UIKit-1912.3/UINavigationController.m:2229
Here is the code thats causing the issue
FirstViewController *firstViewController = [[FirstViewController alloc] initWithNibName:@"FirstViewController.xib" bundle:nil];
[self.navigationController popToViewController:firstViewController animated:YES];
回答1:
Managed to find an example else where which works perfectly.
//Just choose objectAtIndex number to pop to a particulart point on the navigation stack
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:1] animated:YES];
Hope this helps.
回答2:
You cannot pop an instance of a controller that you have not pushed yet, even though it may be identical to another controller to which you would like to return.
In your code snippet, you are trying to pop the stack of the navigation controller to a newly created object. This controller is not on the stack, because you have just created it. Since the navigation controller cannot find a controller that you are looking for, it throws an error.
来源:https://stackoverflow.com/questions/8829905/assertion-failure-while-trying-to-pop-views-from-the-navigation-stack