0
votes

I am trying to dismiss a modal and push a new view controller from the navigation controller, but the code bellow dismisses the navigation controller as well, so there is nothing to push to and the window collapses. This code is inside my routing class:

    func navigateToVC() {
        self.navigationController.presentingViewController.dismiss(animated: false, completion: nil)
        self.navigationController.pushViewController(newVC, animated: false)
    }

So is there a way to dismiss the presenting view controllers while keeping the navigation controller?

1

1 Answers

0
votes

Use this to dismiss presented ViewController,

self.dismiss(animated: true)

Once you dismiss it , that's where you should push ViewController. You can't push after you dismiss your viewController because it's deallocated already.

I recommend creating a delegate and call it from your HomeViewController