开发者

when exactly do Interface Builder items get instantiated?

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:

  1. Instance of RootViewController be created?
  2. This instance be 开发者_Python百科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.


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

It unarchives the nib object graph data and instantiates the objects.

Then almost finally it does:

It sends an awakeFromNib message to the appropriate objects in the nib file that define the matching selector: ... In iOS, this message is sent only to the interface objects that were instantiated by the nib-loading code. It is not sent to File’s Owner, First Responder, or any other proxy objects.

The first method you can get a grip on is awakeFromNib.

To answer your three questions:

  1. During loading of the MainWindo nib file
  2. Yes, have a look at the nib file in interface builder
  3. It all happens before didFinishLaunchingWithOptions


All that will be accomplished before the code reaches application:didFinishLaunchingWithOptions:. The UIApplicationMain() function (called from your app's main() 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜