1
votes

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

I am using Navigation controller.

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)
            })
    }

After dismissing the View Controller, it will not goes to next viewcontroller i.e. DataVC

1
post your current code pleaseVyacheslav
Well you need to use delegate method to achieve thisWings
I added the codeCreative Study

1 Answers

2
votes

If you want to present the view controller then create a protocol in your 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