Search code examples
iphoneuinavigationcontrollerback-button

Prevent the animation when clicking "Back" button in a navigation bar?


My application has a navigation controller and I don't want any animation in it :

  • to prevent an animation when pushing a view, it's easy, via the pushViewController:animated: method

  • but when I click the "back" button on this subview, there's an animation ! KO ! What can I do to prevent this animation ?


Solution

  • More elegant with a category. This assumes you navigation controller object is set in your app delegate. Just put this before your @implementaion in the root view controller.

    #import "AppDelegate.h"
    
    @implementation UINavigationBar (custom)
    - (UINavigationItem *)popNavigationItemAnimated:(BOOL)animated;
    {
    
        AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
    
        [delegate.navController popViewControllerAnimated:NO];
    
        return TRUE;
    }
    
    
    @end