iOS Developer Library — Pre-Release

Developer

UIKit Framework Reference UINavigationBarDelegate Protocol Reference

Options
Deployment Target:

On This Page
Language:

UINavigationBarDelegate

The UINavigationBarDelegate protocol defines optional methods that a UINavigationBar delegate should implement to update its views when items are pushed and popped from the stack. The navigation bar represents only the bar at the top of the screen, not the view below. It’s the application’s responsibility to implement the behavior when the top item changes.

You can control whether an item should be pushed or popped by implementing the navigationBar:shouldPushItem: and navigationBar:shouldPopItem: methods. These methods should return YEStrue if the action is allowed; otherwise, NOfalse.

The screen should always reflect the top item on the navigation bar. You implement the navigationBar:didPushItem: method to update the view below the navigation bar to reflect the new item. Similarly, you implement the navigationBar:didPopItem: method to replace the view below the navigation bar.

Inheritance


Not Applicable

Import Statement


Swift

import UIKit

Objective-C

@import UIKit;

Availability


Available in iOS 2.0 and later.
  • Returns a Boolean value indicating whether the navigation bar should push an item.

    Declaration

    Swift

    optional func navigationBar(_ navigationBar: UINavigationBar, shouldPushItem item: UINavigationItem) -> Bool

    Objective-C

    - (BOOL)navigationBar:(UINavigationBar *)navigationBar shouldPushItem:(UINavigationItem *)item

    Parameters

    navigationBar

    The navigation bar that the item is being pushed onto.

    item

    The navigation item that is being pushed.

    Return Value

    YEStrue if the item should be pushed; otherwise, NOfalse.

    Discussion

    Sent to the delegate before pushing an item onto the navigation bar.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Tells the delegate that an item was pushed onto the navigation bar.

    Declaration

    Swift

    optional func navigationBar(_ navigationBar: UINavigationBar, didPushItem item: UINavigationItem)

    Objective-C

    - (void)navigationBar:(UINavigationBar *)navigationBar didPushItem:(UINavigationItem *)item

    Parameters

    navigationBar

    The navigation bar that the item is being pushed onto.

    item

    The navigation item that is being pushed.

    Discussion

    If pushing an item onto the navigation bar is animated, this method is invoked after the animation ends; otherwise, it is invoked immediately after the push.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Returns a Boolean value indicating whether the navigation bar should pop an item.

    Declaration

    Swift

    optional func navigationBar(_ navigationBar: UINavigationBar, shouldPopItem item: UINavigationItem) -> Bool

    Objective-C

    - (BOOL)navigationBar:(UINavigationBar *)navigationBar shouldPopItem:(UINavigationItem *)item

    Parameters

    navigationBar

    The navigation bar that the item is being popped from.

    item

    The navigation item that is being popped.

    Return Value

    YEStrue if the item should be popped; otherwise, NOfalse.

    Discussion

    Sent to the delegate before popping an item from the navigation bar.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Tells the delegate that an item was popped from the navigation bar.

    Declaration

    Swift

    optional func navigationBar(_ navigationBar: UINavigationBar, didPopItem item: UINavigationItem)

    Objective-C

    - (void)navigationBar:(UINavigationBar *)navigationBar didPopItem:(UINavigationItem *)item

    Parameters

    navigationBar

    The navigation bar that the item is being popped from.

    item

    The navigation item that is being popped.

    Discussion

    If animating the pop operation, this method is invoked after the animation ends; otherwise, it is invoked immediately after the pop.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.