Cover by Vandad Nahavandipoor

Safari, the world’s most comprehensive technology and business learning platform.

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required

O'Reilly logo

5.2. Adding a Navigation Controller to a Storyboard

Problem

You want to be able to manage multiple view controllers inside a storyboard-based application.

Solution

Set a navigation controller as the initial view controller of your storyboard file.

Discussion

If you followed the instructions in Recipe 5.1 and are now running your app on the iPhone Simulator, you’ll see just a white screen with no navigation bar across the top. The reason is that the initial view controller of our storyboard file is a view controller, as opposed to a navigation controller. In order to add a navigation controller to your storyboard-based app, simply follow these steps:

  1. Click on the iPhone storyboard that Xcode created for you. I have named my project Adding a Navigation Bar to a Storyboard. My iPhone storyboard file is MainStoryboard_iPhone.storyboard (the name of the default storyboard file created by Xcode, depending on the version of Xcode you are using, does not have to have any connection to the name of your project). Once you click on this file, Interface Builder will display its contents.

  2. Once the storyboard file is open in IB (Interface Builder), simply double-click on an empty space on the storyboard’s canvas and you will see the content shrink in size and give you more free space to play with, as you can see in Figure 5-6.

    The zoomed out view of an iPhone storyboard

    Figure 5-6. The zoomed out view of an iPhone storyboard

  3. Under the View menu, ...

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required