是否可以在 UINavigationController 中弹出多个视图控制器?假设我想退后两步。
问问题
1878 次
2 回答
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];
于 2012-06-19T13:13:20.793 回答
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 个控制器,因此,我必须在堆栈中采用第三个支持。我真正的解决方案是:
// 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)
}
于 2016-02-05T19:26:17.080 回答