I have an app that uses a view hierarchy managed by multiple UIVIewController
objects (* see notes below) visible in the window at any given time. And as such, I have found that it's essentially arbitrary which one of them receives the shouldAutorotateToInterfaceOrientation:
method call on device rotation from the UIWindow
.
How do I make sure that my UIWindow
object calls my highest-level UIViewController
, not any of it's children?
That seems to be the only way that the rotation layout animation and changes propagate correctly.
In the "View Controller Programming Guide," the iOS documentation states:
In an iOS application, the window object does much of the work associated with changing the current orientation. However, it works in conjunction with the application’s view controllers to determine whether an orientation change should occur at all, and if so, what additional methods should be called to respond to the change. Specifically, it works with the view controller whose root view was most recently added to, or presented in, the window. In other words, the window object works only with the frontmost view controller whose view was displayed using one of the mechanisms described in “Presenting a View Controller’s View.”
However, I have found my experience to be different than this. When UIWindow
is calling shouldAutorotateToInterfaceOrientation
on a particular child view controller, even if I remove and re-add my top-level view controller's view from the UIWindow
, it still calls the same child. In other words, making my top level view controller the most recently added view does not work.
(*) Note: some have pointed out that it's not recommended to use multiple view controllers on the same screen. I assert this is an infeasible goal in various cases. Consider an app that shows two tables (UITableViewControllers) at the same time. Or, in my case, an app that requires a custom view controller that emulates UITabBarController because of graphical/art limitations of the the UITabBar. I do not see a way to refactor my application to only ever be displaying a single UIViewController (or subclass thereof) at any one time.
UPDATE
Not being to find a consistent answer (or exhibited behavior) for what UIViewController the UIWindow object calls upon for interface orientation event handling, I have concluded that the only right answer is no answer at all: just don't use multiple custom UIViewControllers in the same screen (UINavigationController and UITabBarController excepted.)
I'm not sure I can answer your main question but as far as your examples of why you need multiple view controllers, those can just be views. I've made plenty of apps with multiple table views but I use the regular UITableView, not UITableViewController. UITableViewController is pretty much just a default view controller for managing a single UITableView, it doesn't really do much.
It sounds like you might be using view controllers where regular views might suffice.