O'Reilly logo

iOS 6 Programming Cookbook by Vandad Nahavandipoor

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required