iPhone SDK: problem managing orientation with multiple view controllers.

Posted by Tom on Stack Overflow See other posts from Stack Overflow or by Tom
Published on 2009-12-23T17:47:49Z Indexed on 2010/06/14 14:22 UTC
Read the original article Hit count: 209

I'm trying to build an iPhone application that has two subviews in the main window. Each view has its own UIViewController subclass associated with it. Also, within each controller's implementation, I've added the following method:

-(BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)interfaceOrientation {
        return YES;
}

Thus, I would expect both of the views to respond to changes in orientation. However, this is not the case. Only the first view added to the app's main window responds to orientation. (If I swap the order the views are added, then only the other view responds. In other words, either will work--but only one at a time.)

Why is this? Is it not possible to handle the orientation changes of more than one view?

Thanks!

EDIT: Someone else had this question, so I'm copying my solution here:

I was able to address this issue by providing a root view and a root view controller with the method "shouldAutoRotate..." and adding my other views as subviews to the root view. The subviews inherit the auto-rotating behavior, and their associated view controllers shouldn't need to override "shouldAutoRotate..."

© Stack Overflow or respective owner

Related posts about iphone

Related posts about iphone-sdk