9

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?

Cœur
  • 37,241
  • 25
  • 195
  • 267
manoj kashyap
  • 143
  • 2
  • 9
  • VC2 needs to be in a `UINavigationController` then after you present it you can push VC3. The back button will work as expected on VC3, for VC2 you should call [dismiss](https://developer.apple.com/documentation/uikit/uiviewcontroller/1621505-dismiss) when the back button is pressed. Try implementing some of that in code and then update your question. – DoesData Mar 29 '20 at 20:16

2 Answers2

9
//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)
}
Ramprasath Selvam
  • 3,868
  • 3
  • 25
  • 41
2

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

Menaim
  • 937
  • 7
  • 28