UINavigationControllerDelegate Protocol Reference

Conforms to
Framework
/System/Library/Framework/UIKit.framework
Availability
Available in iOS 2.0 and later.
Companion guide
Declared in
UINavigationController.h
Related sample code

Overview

Use a navigation controller delegate (a custom object that implements this protocol) to modify behavior when a view controller is pushed or popped from the navigation stack of a UINavigationController object.

Tasks

Responding to a View Controller Being Shown

Supporting Custom Transition Animations

Instance Methods

navigationController:animationControllerForOperation:fromViewController:toViewController:

Called to allow the delegate to return a noninteractive animator object for use during view controller transitions.

- (id<UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController animationControllerForOperation:(UINavigationControllerOperation)operation fromViewController:(UIViewController *)fromVC toViewController:(UIViewController *)toVC
Parameters
navigationController

The navigation controller whose navigation stack is changing.

operation

The type of transition operation that is occurring. For a list of possible values, see the “UINavigationControllerOperation” constants.

fromVC

The currently visible view controller.

toVC

The view controller that should be visible at the end of the transition.

Return Value

The animator object responsible for managing the transition animations, or nil if you want to use the standard navigation controller transitions. The object you return must conform to the UIViewControllerAnimatorTransitioning protocol.

Discussion

Implement this delegate method when you want to provide a custom animated transition between view controllers as they are added to or removed from the navigation stack. The object you return should be capable of configuring and performing noninteractive animations for the specified view controllers for the specified type of operation over a fixed period of time.

If you want to allow the user to perform interactive transitions, you must also implement the navigationController:interactionControllerForAnimationController: method.

Availability
  • Available in iOS 7.0 and later.
Declared In
UINavigationController.h

navigationController:didShowViewController:animated:

Called just after the navigation controller displays a view controller’s view and navigation item properties.

- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated
Parameters
navigationController

The navigation controller that is showing the view and properties of a view controller.

viewController

The view controller whose view and navigation item properties are being shown.

animated

YES to animate the transition; otherwise, NO.

Availability
  • Available in iOS 2.0 and later.
Declared In
UINavigationController.h

navigationController:interactionControllerForAnimationController:

Called to allow the delegate to return an interactive animator object for use during view controller transitions.

- (id<UIViewControllerInteractiveTransitioning>)navigationController:(UINavigationController *)navigationController interactionControllerForAnimationController:(id<UIViewControllerAnimatedTransitioning>)animationController
Parameters
navigationController

The navigation controller whose navigation stack is changing.

animationController

The noninteractive animator object provided by the delegate’s navigationController:animationControllerForOperation:fromViewController:toViewController: method.

Return Value

The animator object responsible for managing the transition animations, or nil if you want to use the standard navigation controller transitions. The object you return must conform to the UIViewControllerInteractiveTransitioning protocol.

Discussion

Implement this delegate method when you want to provide a custom, interactive transition between view controllers as they are added to or removed from the navigation stack. The object you return should configure the interactivity aspects of the transition and should work with the object in the animationController parameter to start the animations.

Availability
  • Available in iOS 7.0 and later.
Declared In
UINavigationController.h

navigationController:willShowViewController:animated:

Called just before the navigation controller displays a view controller’s view and navigation item properties.

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
Parameters
navigationController

The navigation controller that is showing the view and properties of a view controller.

viewController

The view controller whose view and navigation item properties are being shown.

animated

YES to animate the transition; otherwise, NO.

Availability
  • Available in iOS 2.0 and later.
Declared In
UINavigationController.h

navigationControllerPreferredInterfaceOrientationForPresentation:

Returns the preferred orientation for presentation of the navigation controller, as determined by the delegate.

- (UIInterfaceOrientation)navigationControllerPreferredInterfaceOrientationForPresentation:(UINavigationController *)navigationController
Parameters
navigationController

The navigation controller

Return Value

The preferred orientation for presenting the navigation controller.

Availability
  • Available in iOS 7.0 and later.
Declared In
UINavigationController.h

navigationControllerSupportedInterfaceOrientations:

Returns the complete set of supported interface orientations for the navigation controller, as determined by the delegate.

- (NSUInteger)navigationControllerSupportedInterfaceOrientations:(UINavigationController *)navigationController
Parameters
navigationController

The navigation controller

Return Value

One of the UIInterfaceOrientationMask constants that represents the set of interface orientations supported by the navigation controller.

Availability
  • Available in iOS 7.0 and later.
Declared In
UINavigationController.h

Constants

UINavigationControllerOperation

These constants define the type of navigation controller transitions that can occur.

typedef enum {
   UINavigationControllerOperationNone,
   UINavigationControllerOperationPush,
   UINavigationControllerOperationPop
} UINavigationControllerOperation;
Constants
UINavigationControllerOperationNone

No operation is taking place.

Available in iOS 7.0 and later.

Declared in UINavigationController.h.

UINavigationControllerOperationPush

A view controller is being pushed onto the navigation stack.

Available in iOS 7.0 and later.

Declared in UINavigationController.h.

UINavigationControllerOperationPop

The topmost view controller is being removed from the navigation stack.

Available in iOS 7.0 and later.

Declared in UINavigationController.h.