This might seem like a very simple and easy thing to some of you out there. However I have failed to see any clear and concise explanation of how to do it. So here it goes:
- Create a segue from from the blue controller to the red controller. You do this by hovering over the icon pictured below, and then clicking and dragging while holding the ctrl button, until your over the view controller you want to navigate to.
- You will be presented with the option below, and for this blog post just pick “show”. Then the following arrow below will be created, this is called a segue. Set the name of the segue to something descriptive, in this case I am going to be naming it “ToRed”.
- Create a button on the blue view controller, and create a IB action for that button. Then inside the method call the “performSegue(withIdentifier: “ToRed”, sender: nil)” method where the “withIdentifier” is the name of the segue you want to use to do the navigation.
- Now create a button on the red view controller and create an IB action for that button. However this time inside the method call the “dismiss(animated: true, completion: nil)”. This method allows you to go back to your previous view.
And thats all there is to it. Next time I think I am going to be getting into the topic of passing data back and forth from views, which requires an understanding of protocols and delegates.
You can find the link to the final product here.