2

I have an UITabBarController based app which shows a number of UINavigationController based tabs where I'm loading individual UIViewControllers onto.

To support interface rotation, I'm trying to forward the willRotateToInterfaceOrientation and didRotateFromInterfaceOrientation events to my visible individual UIViewController (which is part of one of the stacks of UINavigationControllers) like this:

// this is in my sub-classed UITabBarController
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {

UIViewController *controller = self.selectedViewController;

// do not pass this to the More controller
if (controller == [self moreNavigationController]) return;

if ([controller isKindOfClass:[UINavigationController class]]) {        
    // although this is not the more controller, the count of view controllers is 0
    // => this view has been pushed onto the moreNavigationController
    if ( [(UINavigationController *)controller viewControllers]==nil || [[(UINavigationController *)controller viewControllers] count]==0 ) {
        controller=[[self moreNavigationController] visibleViewController];
    } else {
        controller = [(UINavigationController *)controller visibleViewController];            
    }
}

[controller didRotateFromInterfaceOrientation:fromInterfaceOrientation];

}

I am seeking confirmation for the piece in the middle of the code. I noticed that individual UIViewControllers which are accessed through the "More" tab are not pushed onto the stack of the UINavigationController that I set up, but onto the MoreNavigationController directly and that although the self.selectedViewController returns my UINavigationController (and not the MoreNavigationController), its viewControllers array has a count of 0. So in order to get my currently displaying UIViewController, I need to get it from the MoreNavigationController.

Am I doing the right thing or am I missing something obvious?

zero0cool
  • 352
  • 4
  • 11

0 Answers0