This tutorial explains how to add more than one screen to your iOS app and link screens together using buttons. We will use a simple example for this tutorial as show below…
Watch the video below or scroll down to read the step-by-step instructions and sample code.
Video
Step 1
Start by creating a new solution (click File > New Solution).
Step 2
Give your app a name, select a minimum supported iOS version and click Next.
Confirm the project and solution names, the project folder location and click Create.
Step 3
Open the Main.storyboard file and drag a Button element on to the screen. Give it a name and change its text value.
Step 4
Drag a Navigation Controller anywhere onto the storyboard. It should look like this…
Step 5
Right-click the Root View Controller and click Delete.
Step 6
Hold down the Ctrl (Control) key while dragging the Navigation Controller screen to your main screen (you will see a blue line linking the two screens together). The select Root from the list of options – this will make the main screen the root screen (the screen that loads first when the app starts running).
Step 7
Now drag a View Controller element onto the storyboard and place it to the right side of your main (root) screen. This will create a new screen which will be the second screen in your app.
Step 8
Hold down the Ctrl (Control) key while clicking and dragging the button on the main screen to the second screen. When you see the list of options appear, select Appear.
Step 9
Now we can add a Button to get from the second screen back to the main screen. Drag a button element on to the second screen. Give it a name. When you name the first element that you add to a new screen, you will see a yellow warning icon. Click it and then you will need to type in the name of the new ViewController for this screen (for example, ScreenTwoViewController)– the name you provide will be the name of a new C# file that will contain the code for this screen. Change the Title property of the button the Back.
Step 10
Now click on the new button on the second screen. Hold down the Ctrl (Control) key while dragging this button to the main screen. Click on Show. This will make the Back button take the user back to the main screen when they tap it.
Lastly, double-click on the main screen’s title so you can rename it.
That’s it! Now you can test out your app.