iOS SDK 4.3 学习笔记 iPhone101 (02)

本文探讨了iOS应用开发中nib文件的加载机制及File's Owner的作用。File's Owner作为nib文件的拥有者,负责该文件内的对象创建与销毁,通常为某个ViewController实例。此外,还介绍了主nib文件的加载流程及其与其他nib文件的区别。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在 iPhone101.pdf P30 关于 File's Owner 有这样一段描述

 
In a nib file, in contrast to the other objects you add to the interface, the File’s Owner object is not created when the nib file is loaded. It represents the object set to be the owner in the method that loads the nib file—in this case, loadNibNamed:owner:options:. This is discussed in more detail in Resource Programming Guide. In your application, the File’s Owner will be the instance of MyViewController.
 
这段话的意思是 nib 文件中的大部分对象都是在 nib 文件被 load 的时候创建的,只有 File’s Owner 对象不是。它是 load 这个 nib 文件的方法 (在这里,是 loadNibNamed:owner:options:)中的 owner 。在 Resource Programming Guide 里有更详细的描述。在这个 application 中,File’s Owner 是 MyViewController 的一个实例。
 
我的理解是 File's Owner 指的是这个 nib 文件的拥有者,它需要负责创建和销毁这个 nib 文件中的对象。loadNibNamed:owner:options: 这个方法我没有找到,估计是在框架中。
 
Resource Programming Guide
 
The Application Loads the Main NIb File
Most of the Xcode project templates for applications come preconfigured with a main nib file already in
place. All you have to do is modify this default nib file in Interface Builder and build your application. At
launch time, the application’s default configuration data tells the application object where to find this nib
file so that it can load it. In applications based on either AppKit and UIKit, this configuration data is located
in the application’s Info.plist file. When an application is first loaded, the default application startup code
looks in the Info.plist file for the NSMainNibFile key. If it finds it, it looks in the application bundle for
a nib file whose name (with or without the filename extension) matches the value of that key and loads it.
 
Each View Controller Manages its Own Nib File
The UIViewController (iOS) and NSViewController (Mac OS X) classes support the automatic loading
of their associated nib file. If you specify a nib file when creating the view controller, that nib file is loaded
automatically when you try to access the view controller’s view. Any connections between the view controller
and the nib file objects are created automatically, and in iOS, the UIViewController object also receives
additional notifications when the views are finally loaded and displayed on screen. To help manage memory
better, the UIViewController class also handles the unloading of its nib file (as appropriate) during
low-memory conditions.
 
For more information about how you use the UIViewController class and how you configure it, see View
Controller Programming Guide for iOS.
 
这两段话的意思是 main nib file 由 application 处理,其他的 nib file 由 UIViewController (iOS) 和 NSViewController (Mac OS X) 处理。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值