覆盖非动态类delaration

时间:2017-03-29 08:00:43

标签: ios swift uitableview xcode8 declaration

使用新的Xcode 8.3,我收到错误:

  

无法覆盖扩展程序

中的非动态类声明

代码行

 override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell

如何避免此警告?

2 个答案:

答案 0 :(得分:4)

这意味着,您不能在扩展中覆盖类似超类委托方法。 你可以做的方法是mv扩展覆盖方法到子类声明。

final class DEMO, UITableViewDataSource, UITableViewDelegate { 
override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
    return sectionHeader
}

override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
    return 40
}

}

答案 1 :(得分:3)

,因为:

扩展程序可以为类型添加新功能,但它们无法覆盖现有功能。

你有两种方式:

1-在类范围内添加您的方法而不是扩展名

2-或为您定义的方法添加动态类型

相关问题