在 swift 中关闭模态视图控制器后弹出视图



我有一个导航控制器A,我在上面推送视图控制器B。从 B 开始,我以模式方式呈现视图控制器 C。在我解雇C之后,我试图回到A。因此,导航流为 A->B ->(当前 ModalView)-> C。我在 B 中尝试了这段代码但没有成功:

 self.navigationController?.popToRootViewControllerAnimated(true)

关于如何实现这一目标的任何建议?

这种情况只发生在iOS7中

谢谢

您必须在 NavigationController 中关闭模态视图控制器 (C) 和 popToRootViewController。在 C 视图控制器中尝试以下代码:

    let presentingVC = self.presentingViewController!
    let navigationController = presentingVC is UINavigationController ? presentingVC as? UINavigationController : presentingVC.navigationController
    navigationController?.popToRootViewControllerAnimated(false)
    self.dismissViewControllerAnimated(true, completion: nil)

在这种情况下,用户将只看到正在关闭模式视图控制器。在导航控制器中弹出到根视图控制器将在背景中进行。

另一个选项是关闭模态视图控制器,然后弹出带有动画的根视图控制器,然后用户将看到所有内容。代码如下:

    let presentingVC = self.presentingViewController!
    let navigationController = presentingVC is UINavigationController ? presentingVC as? UINavigationController : presentingVC.navigationController

    self.dismissViewControllerAnimated(true, completion: { () -> Void in
        navigationController?.popToRootViewControllerAnimated(true)
        return
    })

最新更新