UINavigationItem object manages the buttons and views to be displayed in a
UINavigationBar object. When building a navigation interface, each view controller pushed onto the navigation stack must have a
UINavigationItem object that contains the buttons and views it wants displayed in the navigation bar. The managing
UINavigationController object uses the navigation items of the topmost two view controllers to populate the navigation bar with content.
- iOS 2.0+
- tvOS 2.0+
A navigation item always reflects information about the view controller with which it is associated. The navigation item must provide a title to display when the view controller is topmost on the navigation stack. In addition, the item may contain additional buttons to display on the right (or trailing) side of the navigation bar. You can specify buttons and views to display on the left (or leading) side of the toolbar using the
leftBarButtonItems property but the navigation controller displays those buttons only if there is space available.
backBarButtonItem property of a navigation item reflects the back button you want displayed when the current view controller is just below the topmost view controller. In other words, the back button is not used when the current view controller is topmost.
When specifying buttons for a navigation item, you must use
UIBarButtonItem objects. If you want to display custom views in the navigation bar, you must wrap those views inside a
UIBarButtonItem object before adding them to the navigation item.
For information about how navigation items work together with a navigation controller, custom view controllers, and the navigation bar to display their content, see View Controller Programming Guide for iOS.