Interface Builder 项到底什么时候被实例化?
假设我从 XCode4 中的模板创建一个基于导航的应用程序,那么 MainWindow.xib 中将有一个导航控制器,它有一个子 RootViewController。
那么具体什么时候:
- 创建 RootViewController 的实例?
- 该实例是否作为子级与导航控制器关联?
特别是与 applicationDelegate“didFinishLaunchingWithOptions”方法的时间及其发生时间相关时。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如 plist 中给出的那样,MainWindow 是 Main nib 文件的基本名称。因此,将根据 plist 生成一些隐藏代码,以在启动时加载主窗口 nib 文件。这发生在 didFinishLaunchingWithOptions 之前。
一旦 MainWindow 笔尖加载,就会在后台执行一系列操作,请参阅 笔尖资源编程指南中的对象生命周期。
这些步骤之一是
然后几乎最后它做到了:
您可以掌握的第一个方法是
awakeFromNib
。回答您的三个问题:
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:
所有这些都将在代码到达
application:didFinishLaunchingWithOptions:
之前完成。UIApplicationMain()
函数(从应用程序的main()
函数调用)加载 MainWindow.nib。加载 NIB 文件时,NIB 文件中的所有对象都会被实例化并 请注意,这意味着视图控制器本身已经存在于 application: didFinishLaunchingWithOptions: 中,而视图控制器的视图则不然。第一次访问时。
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.