如何在 swift 中关闭呈现的控制器后推送控制器?

How to push controller after dismiss presented controller in swift?

嘿,我在主控制器中显示了一个控制器 (A),具有演示风格(不是推送),我想在关闭此 (A) 控制器后点击按钮并推送另一个控制器 (B),这种情况发生在主控制器。我正在为这种情况使用协议。有什么想法吗?代码如下。`

//this is dismiss button action

   var segueDelegate: segueFromController?

   @objc func dismissController() {

    self.dismiss(animated: true) {
        self.segueDelegate?.segueFromController()
    }

//and this one is protocol function in main controller


    func segueFromController() {

     let contProfile = ContViewController(collectionViewLayout: UICollectionViewFlowLayout())

           navigationController?.pushViewController(contProfile, animated: true)

}

// and I am making "self" this protocol in main controller's didload

  let aCont = AController()

  override func viewDidLoad() {
            super.viewDidLoad()

            AController.segueDelegate = self
 }

 // protocol

protocol segueFromController { 
  func segueFromController()  
  }

// this is presenting (A) controller code in main page

func openController() {
            let preController = AController()
        preController.modalPresentationStyle = .fullScreen
        self.present(preController, animated: true, completion: nil)

}

首先你需要让这个segueDelegate变弱

protocol segueFromController : class {
func segueFromController()
}
weak var segueDelegate: segueFromController?

func openController() {
            let preController = AController()
         preController.segueDelegate = self
        preController.modalPresentationStyle = .fullScreen
        self.present(preController, animated: true, completion: nil)

}

尝试在没有动画的情况下解雇

self.dismiss(animated: false) {
             self.segueDelegate?.segueFromController()
        }