调用超类的awakeFromNib [英] Calling awakeFromNib of superclass
问题描述
我安装了Xcode 8.0 beta(8S128d)。现在我有一些警告消息:
I installed Xcode 8.0 beta (8S128d). Now I have some warnings with message:
Method possibly missing a [super awakeFromNib] call
。
在哪种情况下我需要调用这个超类的方法?
in all awakeFromNib
methods.
In which case I need to call this method of superclass?
推荐答案
根据 Apple :
您必须调用awakeFromNib的超级实现,以便为父
类提供执行
所需的任何其他初始化的机会。虽然此方法的默认实现没有
,但许多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.
在Xcode 8之前,没有严格的编译器要求,无论Apple如何用Xcode8改变它,如果调用 [super awakeFromNib]
(或 swift中的super.awakeFromNib()
。
Before Xcode 8, there was no strict compiler requirement for this , howeever Apple has changed this with Xcode8, and compiler treats it as error if call to [super awakeFromNib]
(or super.awakeFromNib()
in swift) is missing in awakeFromNib.
所以Swift版本看起来像这样:
So Swift version would look something like this:
func awakeFromNib() {
super.awakeFromNib()
... your magical code ...
}
这篇关于调用超类的awakeFromNib的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!