PreferInterfaceOrientationForPresentation should return a supported interface orientation (iOS 6)

The root window controller of my application window is a subclass of UINavigationController. I added this code to the class:

- (BOOL)shouldAutorotate { return [self.topViewController shouldAutorotate]; } - (NSUInteger)supportedInterfaceOrientations { return [self.topViewController supportedInterfaceOrientations]; } - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return [self.topViewController preferredInterfaceOrientationForPresentation]; } 

In my root UIViewController, I added this code:

 - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return UIInterfaceOrientationPortrait; } - (BOOL)shouldAutorotate { return NO; } - (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationPortrait; } 

When the device is turned to terrain on this view controller, I present the modal view controller. When the device is turned back to the portrait, I have to reject the modal view, but when I do this, I get the following error:

 'preferredInterfaceOrientationForPresentation must return a supported interface orientation!' 

Why am I getting this error?


I tried to return YES from mustAutorotate to the root UIViewController, and now I get an error. "Supported orientations do not have a common orientation with the application, and shouldAutorotate returns YES." This doesn't make sense to me, because UIInterfaceOrientationPortrait is one of the supported orientation apps.

+4
source share
1 answer

In -supportedInterfaceOrientations you need to return the values ​​from the UIInterfaceOrientationMask , not the UIInterfaceOrientation . In particular, it looks like you want UIInterfaceOrientationMaskPortrait

Here's the documentation for -supportedInterfaceOrientations talking about the return value:

Return value

A bitmask that determines which orientations are supported. See "UIInterfaceOrientationMask" for actual bitmask values. The value returned by this method must not be 0.

+14
source

All Articles