IOS 6 ViewController is rotating but shouldn’t

ios6uiviewcontrollerxcode4.5

I want several of my app viewcontrollers to not rotate in iOS 6.0.
This is what i did to make the rotation in iOS 6 possible:

1.) Set the windows rootviewController in application:didFinishLaunchingWithOptions:

self.window.rootViewController = self.tabBarController;

2.) Set the "Supported Interface Orientations" in my Target (in XCode) so i can use all orientations

3.) Implemented the new iOS 6.0 rotation functionality

- (BOOL) shouldAutorotate {

    return YES;
}


-(NSUInteger)supportedInterfaceOrientations{

    return UIInterfaceOrientationMaskAll;
}

4.) For some reasons, i subclassed the UINavigationController and implemented also these new functionalities and used this new NavigationController in stead of the original one.

So far so good, everything works fine and all viewcontrollers are now able to rotate to every orientation. Now i want several viewController to not rotate and only stay in portrait. But when i set the new rotations methods in those specific viewcontrollers like this, it still rotates to every orientation:

- (BOOL) shouldAutorotate {

    return NO;
}


-(NSUInteger)supportedInterfaceOrientations{

    return UIInterfaceOrientationMaskPortrait;
}

Also setting the navigationController's rotationsfunctionality like above doesn't change anything. (All viewcontrollers can rotate to every orientation)

What am i doing wrong?

EDIT:

Also setting the preferred Interfaceorientation doesn't change anything:

- (UIInterfaceOrientation) preferredInterfaceOrientationForPresentation {

    return UIInterfaceOrientationMaskPortrait;
}

Best Answer

If you want all of our navigation controllers to respect the top view controller you can use a category. I've found it easier than subclassing.

@implementation UINavigationController (Rotation_IOS6)

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

-(NSUInteger)supportedInterfaceOrientations
{
    return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}

@end
Related Topic