nib loading的过程,这个是app文档里面有说到资源编程指南

1. 
It loads the contents of the nib file and any referenced resource files into memory。将nib文件和其中引用到的资源文件加载到内存中。


2.It unarchives the nib object graph data and instantiates the objects。


解析nib对象,并对其进行实例化。对实例的对象初始化规则.


    a .By default, objects receive an 
initWithCoder:
 message.默认调用initWithCoder:.对于所有遵循NSCoding协议的对象,包括UIView和UIViewController的子类都会调用这个方法。


    b.Custom views in iOS do not use the 
initWithFrame:
 method for initialization.


   这针对于OS X。iOS的自定义view没有这个方法。所以这里忽略。


    c.Custom objects other than those described in the preceding steps receive an 
init
 message. 也就是其他对象将会调用init方法。

3. It reestablishes all connections (actions, outlets, and bindings) between objects in the nib file。重新为nib文件中的对象简历连接。包括placeholder对象的链接。


outlet的链接。In iOS, the nib-loading code uses the 
setValue:forKey:
 method to reconnect each outlet。iOS中使用的的mvc机制对其进行操作。


Action connections。in iOS, the nib-loading code uses the 
addTarget:action:forControlEvents:
 method of the 
UIControl
 object to configure the action. If the target is 
nil
, the action is handled by the responder chain.使用的是addTarget:action:forControlEvents进行关联。如果目标是nil。那么这个action将会被相应链处理


Bindings。iOS不支持这个

4.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 placeholder objects.这个消息只会发送给再nib loading过程中实例化的对象,而不会给placeholder objects发送这个消息。

5. It displays any windows whose “Visible at launch time” attribute was enabled in the nib file.

下面主要是分析connect的具体建立过程。

我们再xib中拖拽,不管是File's Owner还是再Object中进行的。都会再xib文件中保持这种链接关系。

这个是再object中建立的connect。其中包含有链接的源和目的目标,这个分别用ref做的标记。还有一个label,这就是我们的IBOutLet的名称了。

通过上面的xib的代码可以知道这个链接是和cell关联的,而不是和file‘s owner关联的。

下面再来看看和File’s owner关联的

看到了吧。其实你拖拽的链接关系都记录在了xib中了。再补充一个就是自定义类,很多时候我们都是要使用我们自定义的类。这个是再下面的图里面进行了描述。

到这里就差不多理解,nib再加载过程中是如何生成我们需要的对象,以及如果将IBOutLet和IBAction关联起来的了吧。细心的人可能注意到了File‘s Owner这个东西了,


那么这个对象又扮演着什么样的角色呢?

File's Owner是控制对象,可以说是nib文件的所有者,控制管理可视化对象。


这个和使用代码loadNibNamed中的owner是一样的意思。File's Owner作为占位符,是需要提前再使用nib加载之前存在的。我们一般将File‘s Owner设置为我们自己的Controller类,然后使用initWithNib来生成我们的Controller对象。其实 UIViewController是采用延迟加载的方式,只要需要使用view的时候才会真正的将nib加载起来,这个使用其实底下用的还是
NSBundle
的loadNibNamed这个方法,此时owner就是UIViewController了。这样我们在建立connect的时候就有了对象了。

除了File’s Owner作为那些使用File‘s Owner建立链接必须之外,File’s Owner还有负责内存管理的功能。这个可以参考IBOutlet内存管理,在apple给的文档中也有说明或者google/百度一下也可以。

nib 加载过程分析以及对File’s Owner的理解的更多相关文章

  1. 转:A10/A20 Bootloader加载过程分析

    来自:http://blog.csdn.net/allen6268198/article/details/12905425 A10/A20 Bootloader加载过程分析 注:由于全志A10和A20 ...

  2. 【转】全志A10/A20 Bootloader加载过程分析

    原文 : http://blog.csdn.net/allen6268198/article/details/12905425 从这里开始:http://linux-sunxi.org/Bootabl ...

  3. ios中自定义tableView,CollectionView的cell什么时候用nib加载,什么时候用标识重用

    做了一段时间的iOS,在菜鸟的路上还有很长的路要走,把遇到的问题记下来,好记性不如烂笔头. 在项目开发中大家经常会用到tableView和collectionView两个控件,然而在cell的自定义上 ...

  4. UIViewController XIB/NIB加载过程

    UIViewController中关于nib初始化的函数 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBu ...

  5. seaJS 模块加载过程分析

    先看一个seajs的官方example,  以下以seajs.use('main')为例, 解析加载mod main的过程 //app.html seajs.use("main") ...

  6. Nib加载的方式实现自定义TableView

    实现的效果 实现原理: 通过在主界面中用Bundle 的LoadNib的方式进行自定义窗体文件加载并渲染界面 实现步骤 Step One 创建TableViewCell 窗体 Step Two 定义接 ...

  7. Insmod模块加载过程分析

    一.背景 a) 在进行JZ2440的一个小demo开发的时候,使用自己编译的内核(3.4.2)及lcd模块进行加载时,insmod会提示加载失败因为内核版本不匹配(提示当前内核版本为空),并且显示模块 ...

  8. php编译完php.ini加载问题-Loaded Configuration File (none)

    编译安装php7时指定了--with-config-file-path=/usr/local/php7/etc,修改了 php.ini 的配置后重启,但就是不生效. 出现Loaded Configur ...

  9. 动态加载 移除js file

    动态加载.移除.替换js/css文件 stylesheetjavascriptcssfunctionnull <script language="javascript"> ...

随机推荐

  1. wordpress后台加载速度异常缓慢排查记录(原创)

    原因在于在function.php函数中加入了下面的代码导致了缓慢: //停用版本更新通知remove_action('load-update-core.php', 'wp_update_themes ...

  2. IEEEXtreme 10.0 - Dog Walking

    博客中的文章均为 meelo 原创,请务必以链接形式注明 本文地址 Xtreme 10.0 - Dog Walking 题目来源 第10届IEEE极限编程大赛 https://www.hackerra ...

  3. fastdfs5.11+centos7.2 按照部署(二)【转载】

    https://files.cnblogs.com/files/xiaojf/nginx-1.12.0.tar.gz https://files.cnblogs.com/files/xiaojf/li ...

  4. 使用递归计算n的阶乘n!

    计算n! 观察公式2可以直接使用递归求解 C++代码如下: #include <iostream> using namespace std; unsigned func(unsigned ...

  5. Linux check whether hyperthreading is enabled or not

    There parameters need to be obained: no. of physical CPU; no. of cores on each CPU; no. of all threa ...

  6. Laravel输出JSON时设定输出字段的几种情况总结

    1.如果输出json的时候需要屏蔽某些字段,或则想自定义显示的字段: 1.model里面设置 protected $hidden = ['password'];//要屏蔽的字段 2.model里面设置 ...

  7. php上传中文文件文件名乱码问题

    php上传文件是最最基础的一个技术点,但是深入进去也有不少问题需要解决,这不,上传中文文件后,文件名变成了乱码. 下面是问题代码,很简单: 1.问题代码 html部分: <html> &l ...

  8. [转]Eclipse 的快捷键以及文档注释、多行注释的快捷键

    一.多行注释快捷键 1.选中你要加注释的区域,用ctrl+shift+C 或者ctrl+/ 会加上//注释 2.先把你要注释的东西选中,用shit+ctrl+/ 会加上/*    */注释 3.以上快 ...

  9. VK Cup 2016 - Qualification Round 2 A. Home Numbers 水题

    A. Home Numbers 题目连接: http://www.codeforces.com/contest/638/problem/A Description The main street of ...

  10. bzoj 3969: [WF2013]Low Power 二分

    3969: [WF2013]Low Power Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnli ...