presentingViewController

presentingViewController

我的场景,在我的项目中,我要维护三个ViewController (Main, VC1 and VC2)。在主要ViewController中,我正在维护UIButton,此按钮单击以显示模型视图控制器的VC1。再次,VC1我通过单击操作将UIButton维护为VC2。在VC2显示之后,我需要关闭VC1。

//  presenting ViewController
var presentingViewController: UIViewController! = self.presentingViewController

self.dismissViewControllerAnimated(false) {
      // go back to MainMenuView as the eyes of the user
      presentingViewController.dismissViewControllerAnimated(false, completion: nil)
}

最佳答案

VC2的关闭按钮操作中尝试此操作

var vc = self.navigationController?.presentingViewController
while vc?.presentingViewController != nil {
    vc = vc?.presentingViewController
}
vc?.dismiss(animated: true, completion: nil)

07-26 08:47