关闭并弹出视图控制器

Ric*_*cca 4 uiviewcontroller ios popviewcontrolleranimated swift

我想在视图控制器堆栈上返回两个级别.我按顺序有三个segue:Show,Show,Present Modally.有一个导航控制器正在使用中.从我的第四个观点来看,我想回到第二个视图.我试过用 self.presentingViewController?.presentingViewController?.navigationController?.popViewControllerAnimated(false);

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

第二个只有当第二个和第三个被称为"模态呈现"时才有效.如何让他们与解雇和流行音乐一起工作?

Lyn*_*ott 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);

    });
}
Run Code Online (Sandbox Code Playgroud)