How to go from view to view in iOS

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:

  1. 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.
  2. 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”.
  3. 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.
  4. 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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s