The bar button item on the left side of the navigation bar allows for navigation back to the previous view controller on the navigation stack. The navigation controller updates the left side of the navigation bar as follows:
-
If the new top-level view controller has a custom left bar button item, that item is displayed. To specify a custom left bar button item, set the
leftBarButtonItem
property of the view controller’s navigation item. -
If the top-level view controller does not have a custom left bar button item, but the navigation item of the previous view controller has a valid item in its
backBarButtonItem
property, the navigation bar displays that item. -
If a custom bar button item is not specified by either of the view controllers, a default back button is used and its title is set to the value of the
title
property of the previous view controller—that is, the view controller one level down on the stack. (If there is only one view controller on the navigation stack, no back button is displayed.)
如果 当前的 navigationItem 手动设置了leftBarButtonItem
参数,那么显示这个 buttonItem如果没有 手动设置,那么显示默认的回退按钮,title 就是上个 视图的title , 指向上个 视图,就是栈的下一级。
如果当前视图是 rootView ,可能需要设置 取消 按钮。
navigationBar 右侧按钮一般是手动定制的。-
If the new top-level view controller has a custom right bar button item, that item is displayed. To specify a custom right bar button item, set the
rightBarButtonItem
property of the view controller’s navigation item. -
If no custom right bar button item is specified, the navigation bar displays nothing on the right side of the bar.
-
BarButtonItem
ios 5 有
setBackButtonBackgroundImage:forState:barMetrics: 方法可指定背景,旧的版本只能通过 initWithCustomVIew 指定一个定制的UIButton 来实现。
nil
, the navigation item uses the value in its title
property to create an appropriate back button. If you want to specify a custom image or title for the back button, you can assign a custom bar button item (with your custom title or image) to this property instead. When configuring your bar button item, do not assign a custom view to it; the navigation item ignores custom views in the back bar button anyway.