笨方法学iOS之awakeFromNib的文档的翻译(待补充Demo)

awakeFromNib

Prepares the receiver for service after it has been loaded from an Interface Builder archive, or nib file.

在接收者从IB档案或者nib文件加载后,为服务准备接收者;prepare for sth... 为了什么做准备

The nib-loading infrastructure sends an awakeFromNib message to each object recreated from a nib archive, but only after all the objects in the archive have been loaded and initialized. When an object receives an awakeFromNib message, it is guaranteed to have all its outlet and action connections already established.

nib-loading(我理解是一种行为)的基础结构给每个从nib档案里重新创建的对象,发送一条 awakeFromNib 的消息,但仅仅实在这些对象从档案里加载出来,并且初始化之后,当对象收到awakeFromNib的消息时,可以确保所有的出口、动作的连接都是已经建立好了。

You must call the super implementation of awakeFromNib to give parent classes the opportunity to perform any additional initialization they require. Although the default implementation of this method does nothing, many UIKit classes provide non-empty implementations. You may call the super implementation at any point during your own awakeFromNib method.

你必须调用父类里,awakeFromNib的实现方法,给父类机会去执行他们要求的额外的初始化,尽管这个方法默认的实现里没有做任何事情,很多UIKit类提供了不为空的实现,你可能会调用父类的实现,在你自己的这个awakeFromNib方法的任何地方(实际上就是必须调用)。

During Interface Builder's test mode, this message is also sent to objects instantiated from loaded Interface Builder plug-ins. Because plug-ins link against the framework containing the object definition code, Interface Builder is able to call their awakeFromNib method when present. The same is not true for custom objects that you create for your Xcode projects. Interface Builder knows only about the defined outlets and actions of those objects; it does not have access to the actual code for them.

在IB的测试模式中,这个信息依然会发送给从IB plug-ins中加载的对象,因为plug-ins连接着包含对象定义代码的框架,当呈现时,IB也会调用他们的awakeFromNib方法,但是对于开发者为Xcode工程,创建的定制对象是不一样的,IB只知道那些对象定义好的出口和动作,IB不能访问真实的代码(纯代码创建?);

During the instantiation process, each object in the archive is unarchived and then initialized with the method befitting its type. Objects that conform to the NSCoding protocol (including all subclasses of UIView and UIViewController) are initialized using their initWithCoder: method. All objects that do not conform to the NSCoding protocol are initialized using their init method. After all objects have been instantiated and initialized, the nib-loading code reestablishes the outlet and action connections for all of those objects. It then calls the awakeFromNib method of the objects. For more detailed information about the steps followed during the nib-loading process, see Nib Files in Resource Programming Guide.

在实例化过程中,在档案文件中的每个对象先解档,然后用合适于对象类型的方法,进行初始化。遵循NSCoding协议的对象(包括UIView和UIViewController的子类)都使用initWithCoder方法初始化,所有不遵循NSCoding协议的对象都使用init方法初始化,所有的对象实例化和初始化后,nib-loading代码给所有对象重新建立出口、动作连接,然后调用所有对象的awakeFromNib方法。想要获取更详细的关于nib-loading过程中的步骤信息,去看“Nib Files in Resource Programming Guide”

Because the order in which objects are instantiated from an archive is not guaranteed, your initialization methods should not send messages to other objects in the hierarchy. Messages to other objects can be sent safely from within an awakeFromNib method.

因为对象从档案文件中实例化的顺序不能保证,所以你的初始化方法不能发送消息给这个层级中的其他对象。在awakeFromNib方法中给其他对象发送消息则是安全的。

Typically, you implement awakeFromNib for objects that require additional set up that cannot be done at design time. For example, you might use this method to customize the default configuration of any controls to match user preferences or the values in other controls. You might also use it to restore individual controls to some previous state of your application.

典型的,开发者实现awakeFromNib是为那些要求附加的配置的对象,但是在设计时间,并没有完成。比如,你可能使用这个方法定制任何用来匹配用户偏好的控制的默认配置,或者其他控制的值,也可能使用它来恢复个人的控制,到之前的状态。

你可能感兴趣的:(笨方法学iOS之awakeFromNib的文档的翻译(待补充Demo))