假设您打开了 VC 的 1、2、3、4、5。
比你打开VC 3。
所以你有这样的UINavigationControllercontrollers stack [1, 2, 3, 4, 5, 3]
如果您想返回到 UIViewController #3 的转换,您可以在转换完成 #3 时移除控制器 #3、#4 和 #5(从导航堆栈的中间)。
func viewDidLoad() {
self.navigationController.delegate = self
}
func navigationController(navigationController: UINavigationController, didShowViewController viewController: UIViewController, animated: Bool) {
NSMutableArray *allViewControllers = [NSMutableArray arrayWithArray: navigationController.viewControllers];
//Navigation stack now is [1, 2, 3, 4, 5, 3]. removing VC #3
[allViewControllers removeObjectAtIndex: 2];
//Navigation stack now is [1, 2, 4, 5, 3]. removing VC #4
[allViewControllers removeObjectAtIndex: 2];
//Navigation stack now is [1, 2, 5, 3].removing VC #5
[allViewControllers removeObjectAtIndex: 2];
//Navigation stack now is [1, 2, 3]
navigationController.viewControllers = allViewControllers;
}
从导航堆栈中删除视图控制器后,您将返回从 3 到 2 的过渡