Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7887523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:36:09+00:00 2026-06-03T05:36:09+00:00

UINavigationControllerDelegate methods not called when poping to a view controller that don’t support the

  • 0

UINavigationControllerDelegate methods not called when poping to a view controller that don’t support the current orientation.

I have a UINavigationController as root view controller of my app (initial view controller in my Storyboard).

Let say I push a ViewController A with this for orientation:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

Hence we don’t support any landscape mode. On top of that let’s push another ViewController with code:

@interface B : UIViewController <UINavigationControllerDelegate>
@end

@implementation B
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return YES;   // any orientation supported
}

- (void)viewDidLoad {
    [super viewDidLoad];

    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    UINavigationController *nc = (UINavigationController*)appDelegate.window.rootViewController;
    nc.delegate = self;
}

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    // not always called...
}

- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    // not always called...
}
@end

Now if I have my iPhone in portrait and I push view controller B on top of A, via some touch event, then touch the “back” button in the navbar, everything is fine and the delegate methods are called (I do some stuff there).

But if, when I’m viewing view B, I rotate to landscape, and then hit the back button, those delegate methods are not called!! What’s the point of setting a delegate for the UINavigationController if the methods are called sometimes but not other ? Surely I’m doing something wrong.

I try to put the delegate in other class, like AppDelegate or my MainView, nothing change.

Any ideas ?

demo code here: git://github.com/malaba/NavBarTest.git

From a basic Master-Detail template, modified just as above.

How to show my point ? Here is the step-by-step:

  1. Add some line in Master View (the + top right)
  2. then touch a line to go to details view
  3. See Log in output showing up
  4. Hit back button (labeled “Master”), again log showing up.

Now try to rotate the iPhone (or Simulator) in details view, then go “back” and see no log showing up?!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T05:36:11+00:00Added an answer on June 3, 2026 at 5:36 am

    by Kaspar answer, here is my code in Obj-C.

    .h:

    @interface ProperNavigationController : UINavigationController
    
    @end
    
    @interface ProperNavigationControllerDelegate : NSObject <UINavigationControllerDelegate>
    @property (assign, nonatomic) BOOL wasCalled;
    @end
    

    .m:

    #import "ProperNavigationController.h"
    
    @interface ProperNavigationController ()
    @property (strong, nonatomic) id<UINavigationControllerDelegate> oldDelegate;
    @property (strong, nonatomic) ProperNavigationControllerDelegate *myDelegate;
    @end
    
    @implementation ProperNavigationController
    @synthesize oldDelegate = _oldDelegate;
    @synthesize myDelegate = _myDelegate;
    
    - (void)viewDidLoad {
        [super viewDidLoad];
    
        self.oldDelegate = self.delegate;
        self.myDelegate = [ProperNavigationControllerDelegate new];
        self.delegate = self.myDelegate;
    }
    
    - (UIViewController *)popViewControllerAnimated:(BOOL)animated {
        self.myDelegate.wasCalled = FALSE;
    
        UIViewController *vc = [super popViewControllerAnimated:animated];
    
        if (!self.myDelegate.wasCalled) {
            // if iOS did not call the delegate handler then we must do it
            [self.myDelegate navigationController:self willShowViewController:self.topViewController animated:animated];
            [self.myDelegate navigationController:self didShowViewController:self.topViewController animated:animated];
        }
    
        return vc;
    }
    
    @end
    
    @implementation ProperNavigationControllerDelegate
    @synthesize wasCalled = _wasCalled;     // flag that we use to track whether iOS calls the handlers or we have to 
    
    - (id)init {
        if (self = [super init]) {
           _wasCalled = FALSE; 
        }
        return self;
    }
    
    - (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
        ProperNavigationController *nc = (ProperNavigationController *)navigationController;
        [nc.oldDelegate navigationController:navigationController willShowViewController:viewController animated:animated];
        self.wasCalled = TRUE;  // signal that we have been called
    }
    
    - (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
        ProperNavigationController *nc = (ProperNavigationController *)navigationController;
        [nc.oldDelegate navigationController:navigationController didShowViewController:viewController animated:animated];
    }
    
    @end
    

    it work.

    What do you think ? And should we fill a bug report ?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a UIViewController called LaunchController that is launched in my iPhone app when
I know that viewWillAppear is not called on pop/push views, but I really need
I have a view controller which opens an MFMailComposeViewController modally. When I try to
I have a UIViewController that needs to make use of the UINavigationControllerDelegate , specifically
Given the UINavigationController delegate methods: -(void)navigationController:(UINavigationController*)navigationController (will/did)ShowViewController:(UIViewController*)viewController animated:(BOOL)animated How do you tell or compare
I just want to set up a navigationController with a view that's on the
I have an object that I init like so: pdtd = [[ProfileDataTableDelegate alloc] initWithTableView:profileDataTableView
I may have some misunderstanding regarding the use of the UINavigationControllerDelegate protocol. Here is
Hi I have had a working UIImage picker controller and suddenly it now only
The context: I have three views. One Introductory view, an Upload view and the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.