iOS Developer Library

Developer

UIKit Framework Reference UINavigationControllerDelegate Protocol Reference

Options
Deployment Target:

On This Page
Language:

UINavigationControllerDelegate

Inherits From


Not Applicable

Import Statement


Swift

import UIKit

Objective-C

@import UIKit;

Availability


Available in iOS 2.0 and later

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.

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

    Declaration

    Swift

    optional func navigationController(_ navigationController: UINavigationController, willShowViewController viewController: UIViewController, animated animated: Bool)

    Objective-C

    - (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

    YEStrue to animate the transition; otherwise, NOfalse.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later

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

    Declaration

    Swift

    optional func navigationController(_ navigationController: UINavigationController, didShowViewController viewController: UIViewController, animated animated: Bool)

    Objective-C

    - (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

    YEStrue to animate the transition; otherwise, NOfalse.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later

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

    Declaration

    Swift

    optional func navigationController(_ navigationController: UINavigationController, animationControllerForOperation operation: UINavigationControllerOperation, fromViewController fromVC: UIViewController, toViewController toVC: UIViewController) -> UIViewControllerAnimatedTransitioning?

    Objective-C

    - (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.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later

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

    Declaration

    Swift

    optional func navigationController(_ navigationController: UINavigationController, interactionControllerForAnimationController animationController: UIViewControllerAnimatedTransitioning) -> UIViewControllerInteractiveTransitioning?

    Objective-C

    - (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.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later

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

    Declaration

    Swift

    optional func navigationControllerPreferredInterfaceOrientationForPresentation(_ navigationController: UINavigationController) -> UIInterfaceOrientation

    Objective-C

    - (UIInterfaceOrientation)navigationControllerPreferredInterfaceOrientationForPresentation:(UINavigationController *)navigationController

    Parameters

    navigationController

    The navigation controller

    Return Value

    The preferred orientation for presenting the navigation controller.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later

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

    Declaration

    Swift

    optional func navigationControllerSupportedInterfaceOrientations(_ navigationController: UINavigationController) -> Int

    Objective-C

    - (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.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later

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

    Declaration

    Swift

    enum UINavigationControllerOperation : Int { case None case Push case Pop }

    Objective-C

    typedef enum { UINavigationControllerOperationNone, UINavigationControllerOperationPush, UINavigationControllerOperationPop } UINavigationControllerOperation;

    Constants

    • None

      UINavigationControllerOperationNone

      No operation is taking place.

      Available in iOS 7.0 and later

    • Push

      UINavigationControllerOperationPush

      A view controller is being pushed onto the navigation stack.

      Available in iOS 7.0 and later

    • Pop

      UINavigationControllerOperationPop

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

      Available in iOS 7.0 and later

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later