Home / iPhone Tips and Tutorials

Using Navigation and Tab Bar Controllers

In this article, you have become familiar with creating multiscene applications using modal scene segues and popovers. These are useful and common user interface features, but many iOS applications take a more "structured" approach to scene layout. Two of the most popular application layout methods involve the use of navigation controllers and tab bar controllers. Navigation controllers enable a user to drill down from one screen to another, exposing more detail as they go. You'll see this everywhere in iOS-from the settings app to bookmarks in Safari. The second approach, implementing a tab bar controller, is used for developing apps with multiple functional features, where each tab presents a different scene where the user can interact with a new set of controls.

In this article, you learn about these two controllers and how they can provide a whole new world of interface options for your applications.

Advanced View Controllers

It is rare when an iOS (or any OS) update comes out that makes development simpler. Each release brings new features and new levels of complexity. In iOS 5 and Xcode 4.2, however, two common types of iOS view controllers have become much easier to integrate with your projects: navigation and tab bar controllers.

Previously relying on quite a bit of coding prowess, these advanced view controllers required multiple chapters just to cover basic implementation. Now, it's literally a matter of drag and drop.

Multiscene Development

Creating new view controller subclasses to handle each scene, adding segues, and, if necessary, writing code to manually trigger a segue. The key to being successful in creating multiscene applications is being able to easily exchange information between the different scenes so you can build a cohesive user experience. The more scenes you have, the more planning you need upfront to make sure that everything works the way you want it to.

You created a delegate attribute on one custom view controller subclass and used it to refer to the initial view controller object. Another approach is to create a brand new class that does nothing but manage the information that needs to be shared across scenes. The two types of view controllers that we use in this article include a "parent" view controller that manages multiple scenes that are presented to the user. This parent controller provides an excellent opportunity for exchanging information between scenes, since it is present regardless of which scene is visible. We put this to the test in our sample projects a bit later.

If you need to directly reference one scene's view controller from another, you always can use an outlet to connect them. Just Control-drag from one view controller into the other view controller's interface file and add a property to reference it.

If you attempt to add an outlet and then connect the view controller, Xcode prompts you to create a segue instead. Remember that if you want to create a connection and Xcode starts prompting you to make a segue, you can use the Connections Inspector to precisely target an outlet; no segue will get in the way.

This article is mostly visual-giving your typing fingers a break. The Xcode 4.2 storyboard feature makes what we're about to do possible and enables you to concentrate on coding application logic instead of worrying about getting the right scenes to display when you need them.