Search code examples
swiftxcodeuinavigationcontrollerviewcontrollerback-button

Add a back bar Button between view controllers


I have the following problem. I have the following VC structure

NC-> A->B-->C-->D-->E->F

Where NC is my navigation controller directly connected (->) with the VC A, which is also directly connected with VC B.

Depending on a parameter by tapping on a button in VC B my app decide to go to VC C or to stay in B (-->). I can't therefore, as done before, construct a direct connection between the button and the VC. So I implemented this transaction in VC B.

My problem is that doing like this I do not have a back button on VC C to eventually go back to B. How should I solve this issue?

Thanks?


Solution

  • You CAN create connection between view controllers. In your situation, simply connect B and C with a segue type push. Then when every you want to do this segue, simply call

    //Do some code to decide if you want to call this or not
    self.performSegue(withIdentifier: "identifier", sender: nil)
    

    In this way, when you get to your VC C, you will have a default back button to VC B from your top level NC

    For example

    enter image description here

    enter image description here