对象加载过程:
当您使用 NSNib 或 NSBundle 的方法加载和实例化 nib 文件中的对象时,底层 nib 加载代码执行以下操作:
它将 nib 文件的内容和任何引用的资源文件加载到内存中:
==>整个 nib 对象图的原始数据被加载到内存中,但不是未归档的。
==>任何与 nib 文件关联的自定义图像资源都会被加载并添加到 Cocoa 图像缓存中;请参阅“关于图像和声音资源”。</p>
==>任何与 nib 文件关联的自定义声音资源都会被加载并添加到 Cocoa 声音缓存中;请参阅“关于图像和声音资源”。</p>
它取消归档 nib 对象图数据并实例化对象。它如何初始化每个新对象取决于对象的类型以及它在存档中的编码方式。nib 加载代码使用以下规则(按顺序)来确定要使用的初始化方法。
==>默认情况下,对象会收到一条initWithCoder:
消息。在 OS X 中,标准对象列表包括视图、单元格、菜单和视图控制器,它们由系统提供并在默认 Xcode 库中可用。它还包括使用自定义插件添加到库中的任何第三方对象。即使您更改了此类对象的类,Xcode 也会将标准对象编码到 nib 文件中,然后在对象未归档时告诉归档器交换您的自定义类。
In iOS, any object that conforms to the NSCoding
protocol is initialized using the initWithCoder:
method. This includes all subclasses of UIView and UIViewController whether they are part of the default Xcode library or custom classes you define.
==>Custom views in OS X receive an initWithFrame:
message.
Custom views are subclasses of NSView for which Xcode does not have an available implementation. Typically, these are views that you define in your application and use to provide custom visual content. Custom views do not include standard system views (like NSSlider) that are part of the default library or part of an integrated third-party plug-in.
When it encounters a custom view, Xcode encodes a special NSCustomView object into your nib file. The custom view object includes the information it needs to build the real view subclass you specified. At load time, the NSCustomView object sends an alloc and initWithFrame:
message to the real view class and then swaps the resulting view object in for itself. The net effect is that the real view object handles subsequent interactions during the nib-loading process.
Custom views in iOS do not use the initWithFrame:
method for initialization.
==>Custom objects other than those described in the preceding steps receive an init message.
For detailed explanation you can read apple documentation: at here..