是否可以在UINavigationController中弹出多个viewcontroller?假设我想退两步。
答案 0 :(得分:13)
是的,您可以通过执行类似
的操作来实现这一目标//Your navigation controller
UINavigationController *nav;
//Get the view controller that is 2 step behind
UIViewController *controller = [nav.viewControllers objectAtIndex:nav.viewControllers.count - 2];
//Go to that controller
[nav popToViewController:controller animated:YES];
答案 1 :(得分:1)
<强>夫特强>
在迅捷中,奥马尔提出的相同解决方案是:
// Get the previous Controller.
let targetController: UIViewController = navigationController!.viewControllers[navigationController!.viewControllers.count - 2]
// And go to that Controller
navigationController?.popToViewController(targetController, animated: true)
在我的情况下,我需要支持2个控制器,因此,我必须采用堆栈中的第3个支持。我真正的解决方案是:
// obtaining origin controller
let controller: UIViewController = navigationController!.viewControllers[navigationController!.viewControllers.count - 2]
// If was the expected controller (An enroll action)
if controller is CreateChatViewController {
// I get the previous controller from it, in this case, the 3rd back in stack
let newControllerTarget = navigationController!.viewControllers[navigationController!.viewControllers.count - 3]
// And finally sends back to desired controller
navigationController?.popToViewController(newControllerTarget, animated: true)
}