Apple wrote UIKit, so they can do what they like.
There's a lot of stuff happening under the hood:
- view{Will,Did}{Appear,Disappear}
- View rotations (ugh, headache)
- UIViewControllerWrapperView, which is sometimes the parent of UIViewController.view. Or something.
- UIViewController.navigationController/tabBarController/parentViewController/modalViewController
- Popovers are weird. I'm not sure how they fit in.
If you write your own views, you can probably get away with using UIViewController to control them, but don't expect all the magical behaviour that UIKit gives to a "proper" view controller.
EDIT: I probably shouldn't StackOverflow when it's late. I really mean something like this:
If a view is controlled by a UIViewController, the view controller should exist in the view controller hierarchy (i.e. functions like presentModalViewController:animated:
). This allows UIKit to handle the complicated bits.
When you use something like [fooSubview addSubview:viewController.view]
, UIKit may not do all the things it's supposed to do. What retains viewController
? What happens if there's a memory warning and fooSubview gets unloaded?
If you set something like viewController.view.frame = (CGRect){{0,0},{320,480}}
, you're asking for trouble too: UIViewController sets the frame depending on the current status/navigation/tab/etc bar. It might re-set it, or it might use the frame to decide how to lay out view controllers that you push on top (I've noticed this behaviour; it's messy). If you change viewController.view.transform
, strange things can happen on view rotations, since the view transform is what UIViewController uses for orientation (along with the status bar and a pile of other things).
There's only one well-supported exception I know of:
[window addSubview:viewController.view];
[window makeKeyAndVisible];
(In fact, you can stick viewController.view inside a full-window view inside the window; I'm not sure how that works.)
I think in OS 4.0+ you're supposed to set window.rootViewController = viewController
instead.