Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>First, there is no 'default' implementation of <code>loadView</code>...that method is specifically there for you to override. I do agree that Apple's docs can be a little unclear though. But <code>loadView</code> is called by default whenever the view of the navigation controller is accessed and no view exists (for example: <code>UIView *view = viewController.view</code>). It can also be called manually. But in no situation will <code>loadView</code> have the correct dimensions...that is, in fact, impossible. <code>loadView</code> is called in order for the parent view controller to get the view in the first place so it can size it appropriately. Then once it gets the view it calls <code>viewDidLoad</code>. This is the only code path they can use because views can load from the <code>loadView</code> method or the nib and they must provide a place for additional setup when views are loaded from a nib. Finally, the parent controller will resize the view and call <code>viewWillAppear</code> only when the view will actually appear. For example, if you push a controller on a navController that's off screen, it won't call <code>viewWillAppear</code> until the navController itself is placed on screen. This is done because there's no point in running that code until the controller is actually visible. This is also why you can only ever get the correct dimension in the <code>viewWillAppear</code> method.</p> <p>Now, you noticed that if you add a controller to a standard controller none of this stuff happens. This is because view controllers aren't really intended to contain other view controllers per say. Now in iOS 5, they explicitly support the use of Container View Controllers...which is essentially a view controller that IS designed to contain other view controllers. They added a few 'convenience' methods in iOS 5 to help with this but it's not strictly necessary. The jist of all this is: if you want to add one view controller to another, you will have to manually setup all the appropriate calls to the child view controller (all loading methods, rotation events, memory warning etc). In other words, you have to make your own container view controller. When you do, though, keep in mind what I said before about the code path. It's important that you call child controller methods in the same order Apple does or stuff won't work right.</p> <p>Here's some links to info: <a href="http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html" rel="noreferrer">http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html</a> -Scroll down to: Implementing a Container View Controller</p> <p>Also here for the view controller life cycle, which will help you figure out which calls need to be made in which order: <a href="http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/ViewLoadingandUnloading/ViewLoadingandUnloading.html#//apple_ref/doc/uid/TP40007457-CH10-SW1" rel="noreferrer">http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/ViewLoadingandUnloading/ViewLoadingandUnloading.html#//apple_ref/doc/uid/TP40007457-CH10-SW1</a></p> <p>I do recommend reading the entire View Controller Programming Guide....you can gleam a lot of information from there: <a href="http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/Introduction/Introduction.html#//apple_ref/doc/uid/TP40007457-CH1-SW1" rel="noreferrer">http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/Introduction/Introduction.html#//apple_ref/doc/uid/TP40007457-CH1-SW1</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload