Say I create a navigation based application from the template in XCode4, then there will be in the MainWindow.xib a Navigation Controller, which has as a child the RootViewController.
When exactly would then:
- Instance of RootViewController be created?
- This instance be associated as a child with the Navigation Controller?
In particular when in relation to the timing for the applicationDelegate "didFinishLaunchingWithOptions" method and when it occurs.
All that will be accomplished before the code reaches
application:didFinishLaunchingWithOptions:
. TheUIApplicationMain()
function (called from your app'smain()
function loads MainWindow.nib. When a NIB file is loaded, all the objects in the NIB file get instantiated and the connections between the objects are made.Note that this means that the view controllers themselves already exist in
application: didFinishLaunchingWithOptions:
. The same is not true for the view controller's view. A view controller loads its view lazily the first time it is accessed.As given in the plist the MainWindow is the Main nib file base name. So there is some hidden code which will be generated based on the plist to load the main window nib file on startup. This happens before didFinishLaunchingWithOptions.
As soon as the MainWindow nib is loaded there is a cascade of things that are done in the background, please refer to The Nib Object Life Cycle in the Resource Programming Guide.
One of those steps is
Then almost finally it does:
The first method you can get a grip on is
awakeFromNib
.To answer your three questions: