iOS Programming Cookbook
上QQ阅读APP看书,第一时间看更新

Getting ready

In this recipe, we will see how to build an iOS app which uses a navigation controller. We will see how to push and pop between the view controllers of the navigation controller. We will discuss the navigation bar, which you can see at the top of the navigation controller, and how to customize it.

There is some information that you should know about UINavigationController:

  • The view controllers that it manages are put in a stack; when you push a view controller, you put it at the top of the stack. Also, when you pop a view controller, you remove the top one from the stack and display the preceding one.
  • UINavigationController has three main items--the left item, middle item, and right item.
    • Left Item: By default, you will see a back button (except for the root), and its title is set to the title property of the preceding view controller. You can add a custom button in the by setting leftBarButtonItem or leftBarButtonItems properties in the navigation item of the displayed view controller.
    • Middle Item: By default, a label with the current view controller title property is displayed. You can add custom middle view by setting the titleView property in the navigation item of the displayed view controller.
    • Right Item: This is the same as left item; but by default, there is nothing to display. You can use the rightBarButtonItem or rightBarButtonItems properties in the navigation item.