O'Reilly logo

iOS 7 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

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

When you create a new universal iOS app using the Single View Application template in Xcode, you will get two storyboard files: Main_iPhone.storyboard and Main_iPad.storyboard. If you view them in Interface Builder, you’ll notice that they contain a view controller as their root controller. Figure 6-1 shows the contents of a simple out-of-the-box iPhone storyboard file.

In order to change the root view controller of your storyboard file into a navigation controller, all you have to do is the following:

  1. Select your view controller on the canvas of the storyboard.

  2. From the Edit menu, choose Embed In and then Navigation Controller (see Figure 6-2).

Once you are done, you will notice that the root view controller of your storyboard is now a navigation controller, as shown in Figure 6-3.

A view controller as the root of a storyboard file

Figure 6-1. A view controller as the root of a storyboard file

Embedding your view controller in a navigation controller

Figure 6-2. Embedding your view controller in a navigation controller

A navigation controller is now the root controller of our storyboard

Figure 6-3. A navigation controller ...

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