views:

469

answers:

2

I'm creating an iPad application which should only work in portrait and portait upsidedown modes. For performance reasons in my applicationDidFinishLaunching method I'm creating several viewControllers, and adding them to my main window as subviews. I then hide the ones I don't want to see straight away. There is no tab bar or navigation controller.

My problem is that only the first viewController seems to be receiving the rotate calls. I have verified this by swapping around the order in which I add the subviews to the main window and NSLog's. Is there some way I can force all the controllers to receive the calls?

Some of my views are designed to lay over the top of another view, but this behind view will not always be the same one - so it seems to make sense to have the overlay view in a separate view controller. Am I doing something fundamentally wrong, and that's why it's not behaving as I would expect?

EDIT: The accepted answer for this question seems to indicate the exact problem I'm facing: http://stackoverflow.com/questions/548142/uiviewcontroller-rotate-methods

EDIT 2: Another question that confirms only the "primary" view controller will receive the rotate events. Is it really the case that I need to put all my code into one view controller that has multiple views? http://stackoverflow.com/questions/2423858/multiple-view-controllers-on-screen-at-once

+2  A: 

For someone who comes across this in the future, I solved this by moving items out of the app delegate and into a single view controller. This view controller then contains all the relevant sub-view controllers. By only having the primary view controller as a direct subview of the app delegate window, autorotation went back to working as expected.

alku83
A: 

There is another solution, depending on your design scenario. I had a similar problem, whereby I needed to swap to overlaying view controllers, both of which had to support autorotation.

The solution was very simple. Just put the controllers under different window objects.

All UIWindow object receive device orientation events and propagate them to their sub-view controllers.

So, in the end I just ended up swapping UIWindow(s) and it works perfectly.

cookeecut