我有以下结构:
从mainVC
我提出了一个模态viewController,modalVC
:
let modalVC: ModalVC = ModalVC()
modalVC.modalPresentationStyle = .overCurrentContext
modalVC.modalTransitionStyle = .coverVertical
self.present(modalVC, animated: false, completion: nil)
从modalVC
我提出另一个viewController chatVC
,但这次没有.overCurrentContext
选项:
let chatVC: ChatVC = ChatVC()
self.present(chatVC, animated: false, completion: nil)
此时,我有以下内容:
mainVC
- 以模态显示 - > modalVC
--present - > chatVC
我想解雇chatVC
和modalVC
再次显示mainVC
。
我试过了:
self.presentingViewController?.presentingViewController?.dismiss(animated: false, completion: nil)
没有成功。
有什么想法吗?提前致谢
答案 0 :(得分:1)
有时可能会有点冗长...有助于了解正在发生的事情与您期望发生的事情。试试这样:
if let myPresenter = self.presentingViewController {
if let hisPresenter = myPresenter.presentingViewController {
hisPresenter.dismiss(animated: false, completion: nil)
}
}
如果那不是"工作"你至少可以通过调试来弄清楚什么是不对的。