Lesson 15

Navigation Controllers

A navigation controller is a class that manages the presentation of a stack of view controllers one at a time. The topmost item on the stack is visible, and users can navigate down the stack one view controller at a time. Whenever a view controller is pushed on—or off the navigation controller's stack—iOS applies an appropriate slide animation automatically. Navigation controllers are implemented in the UINavigationController class in the UIKit framework and can be found in several standard applications such as the iOS Mail, and Settings apps.

Adding a Navigation Controller to a Storyboard

To create a navigation controller using the interface editor, simply select the storyboard scene that you want to use as the root view controller of the navigation stack and select Editor arrow Embed In arrow Navigation Controller. You can optionally drag a Navigation Controller object from the Object library to the storyboard. When you create a navigation controller in this manner, Xcode creates a default scene that is set up to act as the root view controller for the navigation controller (see Figure 15.1).

Screenshot of a storyboard screen with Root View Controller tab and Navigation Controller tab selected and Navigation Controller scene with a segue to View Controller scene.

Figure 15.1

In most cases, you will want to use one of the ...

Get Swift iOS 24-Hour Trainer 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.