1
votes

I have created a simple application which has a red background and a button on it (for the purposes of understanding this problem). The app is in landscape mode and being built with iOS6 framework.

I have set the Supported interface orientations pList properties to only have: Landscape (right home button)

If I put the methods -(BOOL)shouldAutorotate and -(NSUInteger)supportedInterfaceOrientations in the view controller and initiate it as the windows rootViewController WITHOUT using a UINavigationController then landscape orientation is achieved.

HOWEVER if I use a subclassed UINavigationController like in the example below and implement -(BOOL)shouldAutorotate and -(NSUInteger)supportedInterfaceOrientations , landscape orientation is NOT achieved and -(BOOL)shouldAutorotate is never called.

I have the following code in my Subclassed UINavigationController:

 //For iOS 5.x and below
 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
 {
  return (interfaceOrientation != UIInterfaceOrientationLandscapeRight);
 }

//For iOS 6.0
-(NSUInteger)supportedInterfaceOrientations
{
 return UIInterfaceOrientationMaskLandscapeRight;
}

-(BOOL)shouldAutorotate
{
return YES;
}

In my appDelegate I have these methods:

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{



self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];

viewController = [[MDViewController alloc] init]; //a very simple viewcontroller containing button on red background which should be in landscape mode
navigationController = [[MDNavigationController alloc] initWithRootViewController:viewController];
[self.window setRootViewController:navigationController.topViewController];

[self.window makeKeyAndVisible];
return YES;
}

-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:  (UIWindow *)window {
   return UIInterfaceOrientationMaskLandscapeRight;
 }

I have seen countless answers to similar questions which I implemented but found that they fail to work. Thanks.

1

1 Answers

2
votes

Shouldn't you be doing this:

[self.window setRootViewController:navigationController];

instead of:

[self.window setRootViewController:navigationController.topViewController];