我应该叫[super awakeFromNib]? [英] Should I call [super awakeFromNib]?

查看:353
本文介绍了我应该叫[super awakeFromNib]?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我实现自己的版本 awakeFromNib ,我应该调用 [super awakeFromNib] 方法?

If i implement my own version of awakeFromNib, should I call [super awakeFromNib] at the end of my method?

推荐答案

awakeFromNib



awakeFromNib for UIKit (iOS):


您必须调用awakeFromNib的super实现,以使父类有机会执行它们所需的任何附加初始化。虽然这个方法的默认实现没有作用,但许多UIKit类提供非空实现。您可以在自己的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 for AppKit(Mac)



(如果使用的是OS X 10.6或更高版本,则为true)

awakeFromNib for AppKit (Mac):

(not true anymore, if using OS X 10.6 or higher)


你应该调用awakeFromNib的super实现,只有当你知道你的父类提供了一个实现。因为应用程序包不提供awakeFromNib方法的默认实现,所以如果父类不实现它,调用super将导致异常。其直接父类为NSObject或NSView的类不需要调用超级实现。对于任何其他类,可以使用NSObject的instancesRespondToSelector:class方法来确定父类是否响应awakeFromNib,如果是,则调用该方法。

You should call the super implementation of awakeFromNib only if you know for certain that your superclass provides an implementation. Because the Application Kit does not provide a default implementation of the awakeFromNib method, calling super results in an exception if the parent class does not implement it. Classes whose immediate parent class is NSObject or NSView do not need to call the super implementation. For any other classes, you can use the instancesRespondToSelector: class method of NSObject to determine if the parent class responds to awakeFromNib and call the method if it does.

这篇关于我应该叫[super awakeFromNib]?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆