4

我想在我的视图控制器堆栈上返回两个级别。我按此顺序设置了三个序列:Show、Show、Present Modally。有一个导航控制器正在使用中。从我的第四个视图我想回到第二个视图。我试过使用 self.presentingViewController?.presentingViewController?.navigationController?.popViewControllerAnimated(false);

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

第二个仅在第二个和第三个连续为“当前模态”时才有效。我怎样才能让他们在解雇和流行的情况下工作?

4

4 回答 4

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);

    });
}
于 2014-12-17T23:00:48.230 回答
3

您可以使用此技术

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

简单干净(展开segues)

@IBAction func unwindAction(segue: UIStoryboardSegue) {
}
于 2015-05-12T05:21:41.083 回答
-1

你这样用。

self.navigationController?.popViewControllerAnimated(true)
于 2015-05-03T19:23:59.580 回答
-1

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

目标 - C

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

迅速

self.navigationController?.dismissViewControllerAnimated(false, completion: nil);
于 2017-08-18T12:33:16.677 回答