加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ios – 调用超类的awakeFromNib

发布时间:2020-12-15 02:01:39 所属栏目:百科 来源:网络整理
导读:我安装了Xcode 8.0 beta(8S128d)。现在我有一些警告与消息: Method possibly missing a [super awakeFromNib] call 在所有awakeFromNib方法中。 我哪种情况我需要调用这个超类的方法? 解决方法 根据 Apple: You must call the super implementation of aw
我安装了Xcode 8.0 beta(8S128d)。现在我有一些警告与消息:

Method possibly missing a [super awakeFromNib] call

在所有awakeFromNib方法中。
我哪种情况我需要调用这个超类的方法?

解决方法

根据 Apple:

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改变了这一点,并且如果awakeFromNib中缺少调用[super awakeFromNib](或者swift中的super.awakeFromNib())),编译器会将其视为错误。

所以Swift版本看起来像这样:

func awakeFromNib() {
   super.awakeFromNib()

   ... your magical code ...
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读