嗨,我正在开发一个我应该去的应用程序:
- 从
UIViewController
1 到UIViewController
2 - 从
UIViewController
2 到UIViewController
3 - 从
UIViewController
3 到UIViewController
4 - 从
UIViewController
4 回到UIViewController
2
我正在使用UINavigationController
. 当我使用时[self.navigationController pushViewController:VC2 animated:NO];
,[self.navigationController popViewControllerAnimated:NO];
一切正常。
但是当我使用[self.navigationController popToViewController:VC2 animated:NO];
from UIViewController
4 应用程序终止说Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Tried to pop to a view controller that doesn't exist.'
以下是我的代码如何弹出到UIViewController
2
for (UIViewController *vc in self.navigationController.viewControllers) {
if ([vc isKindOfClass:[ViewController2 class]]) {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
ViewController2 *VC2 = [storyboard instantiateViewControllerWithIdentifier:@"ViewController2"];
[self.navigationController popToViewController:VC2 animated:NO];
}
}
当我打印导航数组时,它UIViewController
在堆栈中显示 2。我UINavigationController
从编辑器->嵌入->导航控制器中添加了
谁能告诉我为什么会这样?我试图搜索这个问题,但没有任何帮助