我想在视图控制器堆栈上返回两个级别。我按顺序有三个segue:Show,Show,Present Modally。有一个导航控制器正在使用中。从我的第四个观点来看,我想回到第二个视图。我试过用
self.presentingViewController?.presentingViewController?.navigationController?.popViewControllerAnimated(false);
和
self.presentingViewController?.presentingViewController?.dismissViewControllerAnimated(false, completion: nil);
第二个只有当第二个和第三个为“模态”时才有效。如何让他们使用解雇和流行音乐?
答案 0 :(得分:5)
尝试在弹出其他两个之前解除显示的视图控制器:
func dismissThenDoublePop() {
// Get the presenting/previous view
let previousView = self.presentingViewController as UINavigationController
// Dismiss the current view controller then pop the others
// upon completion
self.dismissViewControllerAnimated(true, completion: {
// Get an array of the current view controllers on your nav stack
let viewControllers: [UIViewController] = previousView.viewControllers as [UIViewController];
// Then either pop two view controllers, i.e. pop
// to viewControllers[viewControllers.count - 2], or
// pop to the second view controller in the nav stack,
// i.e. viewControllers[1]. (In this case I've used the
// first option.)
self.navigationController!.popToViewController(viewControllers[viewControllers.count - 2], animated: true);
});
}
答案 1 :(得分:3)
您可以使用此技术
https://stackoverflow.com/a/15839298/1153100
简单干净(Unwind segues)
@IBAction func unwindAction(segue: UIStoryboardSegue) {
}
答案 2 :(得分:-1)
你就像这样使用。
self.navigationController?.popViewControllerAnimated(true)
答案 3 :(得分:-1)
只需调用 dismissViewControllerAnimated 。它会自动关闭所有视图控制器,包括呈现的模型视图控制器。
目标 - C
[self.navigationController dismissViewControllerAnimated:YES completion:nil];
夫特
self.navigationController?.dismissViewControllerAnimated(false, completion: nil);