1

I have 2 view controllers, root, and detail. The root view controller supports landscape and portrait orientation, so it has the following code:

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

The above code works perfectly for the root view controller.

If the root view controller is being displayed, and the user rotates the device into landscape mode, the view adjusts accordingly. From this point, if push my detail view controller on to the stack, it loads in landscape mode. But, it shouldn't, because I have it configured to only support portrait mode. I'm using the code below in my detail view controller:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
bpatrick100
  • 1,261
  • 1
  • 15
  • 23

1 Answers1

0

In your second view controller, replace your code with ...

return UIInterfaceOrientationIsPortrait( interfaceOrientation );
zrzka
  • 20,249
  • 5
  • 47
  • 73
  • That's just a macro that ends up running the same code I already have. However, just for fun I tried it anyway... And I receive the same results. My second view loads in landscape mode, not portrait... – bpatrick100 Feb 16 '11 at 17:17
  • Yes, but it also handles PortraitUpsideDown for you. – zrzka Feb 16 '11 at 17:36
  • And the reason for non functional rotation is that the shouldAutorotate... is called only upon physical device rotation. You should check this question - http://stackoverflow.com/questions/2922919/transitioning-to-landscape-rotation-within-a-uinavigationcontroller – zrzka Feb 16 '11 at 17:37
  • Thanks for the link. I guess the moral to the story is the sdk doesn't play well with navigationcontroller based apps who's views have mixed orientations. The link does go into a tricky work-around that might suffice. However, now I'm just thinking I will go all portrait, or all portrait/landscape. Mixing it is quite a headache, I can see. – bpatrick100 Feb 16 '11 at 22:27