2
是否可以在UINavigationController中弹出多个viewcontroller?假设我想走两步。UINavigationController回到多个步骤
是否可以在UINavigationController中弹出多个viewcontroller?假设我想走两步。UINavigationController回到多个步骤
是的,你可以做到这一点通过执行类似
//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];
斯威夫特
在奥马尔呈现迅速相同的解决方案是:
// 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)
}