关闭并弹出视图控制器



我想在我的视图控制器堆栈上返回两个级别。我按此顺序有三个 segue:显示、显示、呈现模式。正在使用导航控制器。从我的第 4 个视图,我想回到第 2 个视图。我试过使用 self.presentingViewController?.presentingViewController?.navigationController?.popViewControllerAnimated(false);

self.presentingViewController?.presentingViewController?.dismissViewControllerAnimated(false, completion: nil);

第二个仅在第 2 和第 3 个 segue 为"呈现模式"时才有效。我怎样才能让他们在解雇和流行的情况下工作?

在弹出其他两个之前,请尝试关闭显示的视图控制器:

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);
    });
}
您可以使用

此技术

https://stackoverflow.com/a/15839298/1153100

简单干净(放松(

@IBAction func unwindAction(segue: UIStoryboardSegue) {
}

你这样用。

self.navigationController?.popViewControllerAnimated(true)

只需调用dismissViewControllerAnimated。它将自动关闭所有视图控制器,包括呈现的模型视图控制器。

目标 - C

[self.navigationController dismissViewControllerAnimated:YES completion:nil]; 

迅速

self.navigationController?.dismissViewControllerAnimated(false, completion: nil);

相关内容

  • 没有找到相关文章

最新更新