Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Tried to pop to a view controller that doesn't exist.'
使用此代码时
self?.navigationController?.popToViewController(vc2, animated: true)
但是当我尝试简单地弹出它的工作
时self?.navigationController?.popViewController(animated: true)
我正在推动这个viewController,如
navigationController?.pushViewController(vc2, animated: true)
我不确定,推送视图意味着当我尝试popToViewController
时。它有一个视图。请帮忙
答案 0 :(得分:4)
试试这个: -
for obj in (self.navigationController?.viewControllers)! {
if obj is TestViewController {
let vc2: TestViewController = obj as! TestViewController
vc2.data = data
_ =
self.navigationController?.popToViewController(vc2, animated: true)
break
}
}
确保在navigationcontroller堆栈上添加了视图控制器。