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

Get iOS 7 Programming Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.