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

2.12. Implementing Navigation with UINavigationController

Problem

You would like to allow your users to move from one view controller to the other with a smooth and built-in animation.

Solution

Use a UINavigationController widget.

Discussion

If you’ve used an iPhone, iPod touch, or iPad before, chances are that you have already seen a navigation controller in action. For instance, if you go to the Settings app on your phone and then press an option such as Wallpaper (Figure 2-37), you will see the Settings’ main screen get pulled out of the screen from the left and the Wallpaper screen pushing its way into the screen from the right. That is the magic of navigation controllers. They allow you to push view controllers onto a stack and pop them from the stack. The view controller on top of the stack is the top view controller and is the one seen by the user at that moment. So only the top view controller gets displayed to the user, and is changed either by popping (removing) it or by pushing another view controller onto the stack.

Now we are going to add a navigation controller to our project, but we need a project first. Please follow the instructions in Recipe 2.10 to create an empty application with a simple view controller. In this recipe, we will expand on Recipe 2.10. Let’s start with the .h file of our app delegate:

Settings view controller pushing the Wallpaper view controller

Figure 2-37. Settings view controller pushing the Wallpaper view 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