By the end of this article you will have completed a really fun project, while also learning how navigation works in iOS. Start by creating a new Single View Application project in Xcode. Go to the storyboard and select the view controller. On the Xcode menu, go to Editor → Embed In → Navigation Controller. You will notice now the view has a navigation bar. Inside the view drag a text view and two buttons. Set the necessary constraints. Write You’re on the Home screen. What do you want to do next? in the text view. Name one of the buttons Go to scene 2 and the other Go to scene 3.
Now copy and paste four times our view controller so we can preserve its elements. To copy an entire view controller, with your mouse or touchpad drag a rectangle around it in the Storyboard so everything is selected, then just press command-c followed by command-v. The new view controller will be pasted on top of the old one, so just drag it aside to see them both. Let’s give names to all the scenes in the Attributes Inspector → Title so they will now show as scene 1, scene 2, scene 3, scene 4, scene 5.
If you run the project and navigate all the way to scene 4 or scene 5 and then click the Start Over button, you will notice that deallocated is printed out twice, because the scene 4/5 is dismissed first, and then scene 3 is dismissed before reaching the home scene (scene 1). You now have the barebones for creating a great adventure game with lots and lots of scenes. To make the app more interesting, you could add some images beside the existing text. To make it even more interesting you could use a table view on the home scene to present a set of different adventures, instead of just this one.