init/initwithcoder/initwithframe

initWithCoder:

这个方法是所有归档对象的初始化方法。由于存储在nib中的对象都会被归档,所以,当从一个nib文件内加载对象时,这个初始化方法会被用到。当这个方法被调用后,nib中的对象将会被序列化,不过outlets和actions不会被连接。UIViewController从nib文件中被创建时,这个方法会被调用。

awakeFromNib
This method is called on every single object that is unarchived from a nib file, after all outlets/actions have been set up. If initWithCoder: is the beginning of the nib unarchiving process, then awakeFromNib is the end. It signals to the object that all objects have been unarchived and that all of its connections are available. In the context of UIViewController, it signals to the view controller that it's now ready to be used.

当nib中的对象被unarchived时,这个方法在所有的outlets/actions已经被设置后会被调用。如果initWithCoder:是nib文件unarchived的开始,那么awakeFromNib就是结束点,它是一个对象已经被unarchived并且它所有的关联都可用到象征,在UIViewController上下文,它是这个viewController可用的象征。

When creating a UIViewController, you have two options. The first is to create it in code. If you go this way, you use initWithNibName:bundle:. The second is to create one by loading a nib. If you go this way, the nib loading process automatically invokes both initWithCoder: and awakeFromNib.

当创建一个UIViewController,你可以有2个选择。第一个就是通过代码创建,如果用这个方式,用initWithNibName:bundle:。第二个方法是通过加载nib文件的方式创建,如果用这个方式,这个nib文件的加载进程中会自动调用initWithCoder和awakeFromNib方法

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值