这个方法是所有归档对象的初始化方法。由于存储在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方法