How to Push from presented ViewController?

Viewed 2766

What I want to do is:

VC1 -> present VC2 -> push VC3

this is the normal flow I want to make.

after that on back button(on each VC have back button)

I required to show user as moving back:

VC3 -> present VC2 -> VC1

How do I achieve this kind of navigation in Swift 5?

2 Answers
//VC1
@IBAction func presentVC2() {
    let vc2 = VC2()
    vc2.modalPresentationStyle = .fullScreen
    self.present(vc2, animated: true, completion: nil)
}

//VC2
@IBAction func presentVC3() {
    let vc3 = VC3()
    let navController = UINavigationController(rootViewController: vc3) //Add navigation controller
    navController.modalPresentationStyle = .fullScreen
    self.present(navController, animated: true, completion: nil)
}

//VC3
@IBAction func navigationVC4() {
    let vc4 = VC4()
    self.navigationController?.pushViewController(vc4, animated: true)
}

From Apple Documentation:

The presenting view controller is responsible for dismissing the view controller it presented.

so you need to dismiss it first then you can navigate to the viewController you want and you can implement it in the completion of dismiss function

Related