iPhone OS Reference Library Apple Developer Connection spyglass button

UINavigationItem Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/UIKit.framework
Availability
Available in iPhone OS 2.0 and later.
Declared in
UINavigationBar.h
Related sample code

Overview

The UINavigationItem class encapsulates information about a navigation item pushed on a UINavigationBar object’s stack. A navigation bar is a control used to navigate hierarchical content. A UINavigationItem specifies what is displayed on the navigation bar when it is the top item and also how it is represented when it is the back item.

Use the initWithTitle: method to create a navigation item specifying the item’s title. The item cannot be represented on the navigation bar without a title. Use the backBarButtonItem property if you want to use a different title when this item is the back item. The backBarButtonItem property is displayed as the back button unless a custom left view is specified.

The navigation bar displays a back button on the left and the title in the center by default. You can change this behavior by specifying either a custom left, center, or right view. Use the setLeftBarButtonItem:animated: and setRightBarButtonItem:animated: methods to change the left and right views; you can specify that the change be animated. Use the titleView method to change the center view to a custom view.

These custom views can be system buttons. Use the UIBarButtonItem class to create custom views to add to navigation items.

Tasks

Initializing an Item

Getting and Setting Properties

Customizing Views

Properties

For more about Objective-C properties, see “Properties” in The Objective-C Programming Language.

backBarButtonItem

The bar button item to use when this item is represented by a back button on the navigation bar.

@property(nonatomic, retain) UIBarButtonItem *backBarButtonItem
Discussion

When this item is the back item of the navigation bar—when it is the next item below the top item—it may be represented as a back button on the navigation bar. Use this property to specify the back button. The target and action of the back bar button item you set should be nil. The default value is a bar button item displaying the navigation item’s title.

Availability
See Also
Declared In
UINavigationBar.h

hidesBackButton

A Boolean value that determines whether the back button is hidden.

@property(nonatomic, assign) BOOL hidesBackButton
Discussion

YES if the back button is hidden when this navigation item is the top item; otherwise, NO. The default value is NO.

Availability
See Also
Declared In
UINavigationBar.h

leftBarButtonItem

A custom bar item displayed on the left of the navigation bar when this item is the top item.

@property(nonatomic, retain) UIBarButtonItem *leftBarButtonItem
Availability
See Also
Related Sample Code
Declared In
UINavigationBar.h

prompt

A single line of text displayed at the top of the navigation bar.

@property(nonatomic, copy) NSString *prompt
Discussion

The default value is nil.

Availability
Related Sample Code
Declared In
UINavigationBar.h

rightBarButtonItem

A custom bar item displayed on the right of the navigation bar when this item is the top item.

@property(nonatomic, retain) UIBarButtonItem *rightBarButtonItem
Availability
See Also
Related Sample Code
Declared In
UINavigationBar.h

title

The navigation item’s title displayed in the center of the navigation bar.

@property(nonatomic, copy) NSString *title
Discussion

The default value is nil.

Availability
See Also
Related Sample Code
Declared In
UINavigationBar.h

titleView

A custom view displayed in the center of the navigation bar when this item is the top item.

@property(nonatomic, retain) UIView *titleView
Discussion

If this property value is nil, the navigation item’s title is displayed in the center of the navigation bar when this item is the top item. If you set this property to a custom title, it is displayed instead of the title. This property is ignored if leftBarButtonItem is not nil.

Custom views can contain buttons. Use the buttonWithType: method in UIButton class to add buttons to your custom view in the style of the navigation bar. Custom title views are centered on the navigation bar and may be resized to fit.

The default value is nil.

Availability
Declared In
UINavigationBar.h

Instance Methods

initWithTitle:

Returns a navigation item initialized with the specified title.

- (id)initWithTitle:(NSString *)title

Parameters
title

The string to set as the navigation item’s title displayed in the center of the navigation bar.

Return Value

A new UINavigationItem object initialized with the specified title.

Discussion

This is the designated initializer for this class.

Availability
  • Available in iPhone OS 2.0 and later.
See Also
Declared In
UINavigationBar.h

setHidesBackButton:animated:

Sets whether the back button is hidden, optionally animating the transition.

- (void)setHidesBackButton:(BOOL)hidesBackButton animated:(BOOL)animated

Parameters
hidesBackButton

YES if the back button is hidden when this navigation item is the top item; otherwise, NO.

animated

YES to animate the transition; otherwise, NO.

Availability
  • Available in iPhone OS 2.0 and later.
See Also
Declared In
UINavigationBar.h

setLeftBarButtonItem:animated:

Sets the custom bar item, optionally animating the transition to the view.

- (void)setLeftBarButtonItem:(UIBarButtonItem *)item animated:(BOOL)animated

Parameters
item

A custom bar item to display on the left of the navigation bar.

animated

YES to animate the transition to the custom bar item when this item becomes the top item; otherwise, NO.

Discussion

If two navigation items have the same custom left or right bar items, the views remain stationary during the transition when an item is pushed or popped.

Availability
  • Available in iPhone OS 2.0 and later.
See Also
Declared In
UINavigationBar.h

setRightBarButtonItem:animated:

Sets the custom bar item, optionally animating the transition to the view.

- (void)setRightBarButtonItem:(UIBarButtonItem *)item animated:(BOOL)animated

Parameters
item

A custom bar item to display on the right of the navigation bar.

animated

YES to animate the transition to the custom bar item when this item becomes the top item; otherwise, NO.

Discussion

If two navigation items have the same custom left or right bar items, the bar items remain stationary during the transition when an item is pushed or popped.

Availability
  • Available in iPhone OS 2.0 and later.
See Also
Declared In
UINavigationBar.h


Last updated: 2008-06-09

Did this document help you? Yes It's good, but... Not helpful...