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.
Start by creating a new solution (click File > New Solution).
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.
Open the Main.storyboard file and drag a Button element on to the screen. Give it a name and change its text value.
Drag a Navigation Controller anywhere onto the storyboard. It should look like this…
Right-click the Root View Controller and click Delete.
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).
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.
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.
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.
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.