Interface Builder 项到底什么时候被实例化?

发布于 2024-11-03 07:02:22 字数 264 浏览 3 评论 0原文

假设我从 XCode4 中的模板创建一个基于导航的应用程序,那么 MainWindow.xib 中将有一个导航控制器,它有一个子 RootViewController。

那么具体什么时候:

  1. 创建 RootViewController 的实例?
  2. 该实例是否作为子级与导航控制器关联?

特别是与 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:

  1. Instance of RootViewController be created?
  2. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

何其悲哀 2024-11-10 07:02:22

正如 plist 中给出的那样,MainWindow 是 Main nib 文件的基本名称。因此,将根据 plist 生成一些隐藏代码,以在启动时加载主窗口 nib 文件。这发生在 didFinishLaunchingWithOptions 之前。

一旦 MainWindow 笔尖加载,就会在后台执行一系列操作,请参阅 笔尖资源编程指南中的对象生命周期

这些步骤之一是

它取消归档 nib 对象图
数据并实例化对象。

然后几乎最后它做到了:

它发送一条 awakeFromNib 消息到
笔尖中的适当物体
定义匹配的文件
选择器:
...
在 iOS 中,此消息仅发送至
接口对象
由笔尖加载代码实例化。
首先它不会发送给文件所有者
响应者,或任何其他代理对象。

您可以掌握的第一个方法是awakeFromNib

回答您的三个问题:

  1. 在加载 MainWindo nib 文件期间
  2. 是的,查看界面生成器中的 nib 文件
  3. 这一切都发生在 didFinishLaunchingWithOptions 之前

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
溺深海 2024-11-10 07:02:22

所有这些都将在代码到达 application:didFinishLaunchingWithOptions: 之前完成。 UIApplicationMain() 函数(从应用程序的 main() 函数调用)加载 MainWindow.nib。加载 NIB 文件时,NIB 文件中的所有对象都会被实例化并 请注意,这意味着视图控制器本身已经存在于 application: 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文