Assertion failure while trying to pop views from the navigation stack

爷,独闯天下 提交于 2019-12-22 20:03:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!