我的场景,在我的项目中,我要维护三个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)