原贴:http://blog.csdn.net/weilaizhuan/article/details/51063275
当我们做app的时候有时候会遇到这样的需求,根视图是A一个“个人信息” 页面,点击头像会push到“个人详细信息”的B页面,当我们点击某一个详细的信息进行修改时会push到“修改信息”的C页面(或者会有详细的地区选择的D、E、F等等)。修改后我们需要Pop到B视图,然而苹果给我们提供的有两种方法
1、推出到根视图控制器
- - (nullable NSArray<__kindof UIViewController *> *)popToRootViewControllerAnimated:(BOOL)animated;
2、推出到指定的视图控制器
- - (nullable NSArray<__kindof UIViewController *> *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated;
然而当我们直接用第二种方法时系统会“崩溃”,提示
- Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Tried to pop to a view controller that doesn't exist.'
![](http://static.blog.csdn.net/images/save_snippets_01.png)
- for (UIViewController *controller in self.navigationController.viewControllers) {
- if ([controller isKindOfClass:[ReviseUserInformationViewController class]]) {
- ReviseUserInformationViewController *revise =(ReviseUserInformationViewController *)controller;
- [self.navigationController popToViewController:revise animated:YES];
- }
- }
压入栈了,那我们就可以在栈内查找