Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

preferredInterfaceOrientationForPresentation must return a supported interface orientation (iOS 6)

My application window's root view controller is a subclassed UINavigationController. I have 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 have added this code:

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationPortrait;
}

- (BOOL)shouldAutorotate
{
    return NO;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationPortrait;
}

When the device is rotated to landscape on this view controller, I present a modal view controller. When the device is rotated back to portrait, I am supposed to dismiss the modal view, but when I do I get the following error:

'preferredInterfaceOrientationForPresentation must return a supported interface orientation!'

Why am I getting this error?


I tried returning YES from shouldAutorotate in the root UIViewController, and now I get the error 'Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES'. This makes no sense to my, because UIInterfaceOrientationPortrait is one of the applications supported orientations.

like image 549
Darren Avatar asked Dec 09 '22 19:12

Darren


1 Answers

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

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

Return Value

A bit mask specifying which orientations are supported. See “UIInterfaceOrientationMask” for valid bit-mask values. The value returned by this method must not be 0.

like image 90
Andrew Hershberger Avatar answered Dec 11 '22 09:12

Andrew Hershberger