-1

THIS IS NOT A DUPLICATE QUESTION. A final working solution has NOT been provided yet. Please do not CLOSE this question until I have accepted an answer or found and provided my own solution for this. Thanks!

================================================================== Using Xcode 4.5.1, I have a tab-bar app with 5 tabs in it. Each tab contains a UINavigationController. The entire App thus needs to be viewed in Portrait mode with the exception of one sole ViewController - a "modal" VC that opens in full screen and that's intended to be viewed in Landscape mode.

This worked perfectly well in iOS5 - I simply used the following code in that one particular ViewController:

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
   return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

But now the App crashes, and gives this error:

Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation',    
reason: 'preferredInterfaceOrientationForPresentation must return a supported interface orientation!'

Any suggestions?

sirab333
  • 3,662
  • 8
  • 41
  • 54
  • Answer here: http://stackoverflow.com/questions/12690963/preferredinterfaceorientationforpresentation-must-return-a-supported-interface-o – keno Nov 01 '12 at 03:52

4 Answers4

5

Kindly check the What version xcode you used.

You used XCODE 4.5: shouldAutorotateToInterfaceOrientation delegate Depreciated.

You use following lines in your project.

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAll;
    }

-(BOOL)shouldAutorotate
{
    return YES;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationPortrait;
}
  • Make sure to put this in the top-most viewController in your stack. – ArtSabintsev Nov 01 '12 at 04:13
  • not working. 1) in the `supportedInterfaceOrientations` method you return `MaskAll` - should this be done in the P-List too? or should P-List support only Portrait? 2) When you say 'top-most viewController' - would that be the UINavigationController or the tabBarController? If its the tabBarController, its init'd in AppDelegate file - so you put this code there, in AppDelegate? – sirab333 Nov 01 '12 at 04:21
  • `*** Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'preferredInterfaceOrientationForPresentation must return a supported interface orientation!' ` – sirab333 Nov 01 '12 at 04:24
  • http://stackoverflow.com/questions/12404556/interface-orientation-in-ios-6-0 check this link –  Nov 01 '12 at 04:26
  • http://stackoverflow.com/questions/12778636/understanding-ios-6-interface-orientation-change –  Nov 01 '12 at 04:30
1

You need to use this to avoid iOS6 crash..

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_6_0
- (NSUInteger)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window
{
    return UIInterfaceOrientationMaskAllButUpsideDown; //Getting error here? then update ur xcode to 4.5+
}
#endif
Guru
  • 21,652
  • 10
  • 63
  • 102
0

Remember one thing. In iOS 6

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

is deprecated.

You cannot use it in iOS 6. For supporting different interface orientation in viewControllers of a UINavigationController you need to subclass the UINavigationController or make a Category of it.

Evol Gate
  • 2,247
  • 3
  • 19
  • 37
  • thank you - I know `shouldAutorotateToInterfaceOrientation` is deprecated - can you further explain having to subclass `UINavigationController`? Sample code? Would I have to do this for every `UINavigationController` in my project? I have dozens of 'em... – sirab333 Nov 01 '12 at 04:23
  • All you need to do is subclass the UINavigationController and use that subclass as your navigation controller in your app. You have to do this only once in your app. Have a look at this link: http://www.wmdeveloper.com/2012/09/ios-6-and-interface-orientation.html – Evol Gate Nov 01 '12 at 04:31
  • OK - I'll give it a shot. That's pretty crazy though - having to subclass UINavigationController. Having to jump through hoops to make something that was once so simple work again. How very _**Apple**_. (But thank you for the advice of course:-)) – sirab333 Nov 01 '12 at 04:38
  • That's true, Apple is making developers go crazy these days :) – Evol Gate Nov 01 '12 at 04:39
0

Code looks OK. it Should not have crashed for just that methods. problem coud be in another part of code. However ,here i would like to tell you. Above shouldAutorotateToInterfaceOrientation methods orientation methods has deprecated in iOS 6. if you want to know more how to fix orientation issue you should take a look of this

Community
  • 1
  • 1
Kamar Shad
  • 6,089
  • 1
  • 29
  • 56