initWithNibName:bundle
定义:is a message sent to a view (or window) controller in order to create the controller; thus, before the nib is loaded;
awakeFromNib
定义:is a message sent to every object in a nib after all of its outlets are hooked up; thus, after the nib is loaded;
当一个.nib或.storyboard文件被加载时,该文件中的每个对象都会收到awakeFromNib消息;
换句话说,通过.nib或.storyboard创建view对象时,会执行awakeFromNib;
ViewController的初始化
1、代码初始化:完全没有xib,纯代码实现加载;
2、半代码初始化:有xib,通过代码调用xib来实现初始化;
使用:initWithNibName:bundle
3、完全IB初始化:有xib,然后将其加入到其他xib中,如tabbarController中加入多个由xib设计多ViewController,这些是通过IB来初始化的;
使用:awakeFromNib
注意到:上面三种初始化后都会调用viewDidLoad
viewDidLoad:
当view对象被加载到内存时,就会执行viewDidLoad