IO6 doesn't call -(BOOL)shouldAutorotate

ios, ios6, iphone, objective-c, uiinterfaceorientation

Solution

It's because neither `UITabBarcontroller` nor `UINavigationController` is passing shouldAutorotate to its visible view controller. To fix that you may subclass either UITabBarController or UINavigationController and forward shouldAutorotate from there:

In your subclassed UITabBarController add:

- (BOOL)shouldAutorotate
{
    return [self.selectedViewController shouldAutorotate];
}

In your subclassed UINavigationController add:

- (BOOL)shouldAutorotate
{
    return [self.visibleViewController shouldAutorotate];
}

Problem

I have some views in my app that I don't want to suport orientation. In `didFinishLaunchingWithOptions` I add navigation: ``` ... UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:self.viewController]; self.window.rootViewController = nav; [self.window makeKeyAndVisible]; ... ``` In each `ViewController` I have `UITabBar` (I don't know if this is important). In the first view controller I add: ``` -(BOOL)shouldAutorotate { return NO; } - (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskPortrait; } ``` `supportedInterfaceOrientations` is called at the view loading but `shouldAutorotate` doesn't call as I rotate device. What am I missing here?

Original source

Related problems