如何解除overCurrentContext模式viewController及其子节点?

时间:2017-07-31 17:35:41

标签: ios swift

我有以下结构:

  • 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

我想解雇chatVCmodalVC再次显示mainVC

我试过了:

self.presentingViewController?.presentingViewController?.dismiss(animated: false, completion: nil)

没有成功。

有什么想法吗?提前致谢

1 个答案:

答案 0 :(得分:1)

有时可能会有点冗长...有助于了解正在发生的事情与您期望发生的事情。试试这样:

    if let myPresenter = self.presentingViewController {

        if let hisPresenter = myPresenter.presentingViewController {

            hisPresenter.dismiss(animated: false, completion: nil)

        }

    }

如果那不是"工作"你至少可以通过调试来弄清楚什么是不对的。