iOS Tutorials: Passing Information to a Second View Controller

In this tutorial, we will learn how to pass information from the first view controller to the second view controller. In other words, whatever information that are being stored on the first view controller will then appear again on the second view controller.

On your Xcode, go to File > New > Project to create a new blank project.

Go ahead and give your project any name. For mine, I put Pass Information. You could go ahead and put in the required information as your own information.

Drag another View Controller into the Main.storyboard. For the first view controller, we will be needing TextField and Button while on the second view controller, we are gonna need a Label and a Button. By now you should have also created a new View Controller class which in my case was given the name SecondViewController.

Make sure that there you have two ViewController on your Main.storyboard and two .swift file. On the Main.storyboard, click on the Second View Controller and some of the settings will popped up on the right. We want to make sure that the Second View Controller is connected to SecondViewController.swift or else we won’t be able to connect any of those outlets to the swift file.

Connect those label and button to your ViewController except for the button on first view controller. Lets proceed to the coding section for the first ViewController

The SecondViewController.swift code should look like the following:

Hopefully you’ll be able to understand from the code here. Happy Coding!

The following code is posted on GitHub

  • Article By :
    Founder of DaddyCoding. Studied Computer Science, Information System and Information Technology at BYU-Hawaii. Currently spending most of my time researching and learning on helping to expose making iOS apps.

Random Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*