簡體   English   中英

快速退出導航控制器后,如何顯示另一個視圖控制器?

[英]How to present another view controller after dismiss from navigation controller in swift?

快速退出導航控制器后,如何顯示另一個視圖控制器?

我正在使用導航控制器。

ViewController1.swift

func pushTo(viewController: UIViewController) {
        let showLocalPwd = self.storyboard?.instantiateViewController(withIdentifier: "LocalPwdVC") as! LocalPwdVC
        self.navigationController?.present(showLocalPwd, animated: true, completion: nil)
}

ViewController2.swift

    @IBAction func btnVerify(_ sender: Any)
    {
            self.dismiss(animated: true, completion: {
                 let vc = self.storyboard.instantiateViewController(withIdentifier: "DataVC") as! DataVC
            self.navigationController.pushViewController(vc, animated: true)
            })
    }

取消視圖控制器后,它將不會轉到下一個視圖控制器,即DataVC

如果要顯示視圖控制器,請在dismissViewController中創建一個協議

protocol dismissViewController {
func presentCompletedViewController()
 }
// Then create a delegate 
   var delegate = dismissViewController? = nil
// If you are using action to dismiss your ViewController then call delegate

     @IBAction func YourButton(_ sender: Any) {
    self.dismiss(animated: true) {
        self.delegate!.presentCompletedViewController()
    }
}

//And then call this in your main or homeViewController
  class HomeViewController: UIViewController, dismissViewController {
 func presentCompletedViewController(){
// enter code to present view controller
 }
 // And at last don't forget to call delegate
    yourVc.delegate = self
    you need to call this delegate in which you are presenting your dismissViewController

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM