when exactly do Interface Builder items get instantiated?

空扰寡人 提交于 2019-12-06 11:26:59

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!