2
有了新的Xcode 8.3,我得到错误:覆盖非动态类delaration
不能从分机
中的代码行覆盖非动态类声明
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
如何避免此警告?
有了新的Xcode 8.3,我得到错误:覆盖非动态类delaration
不能从分机
中的代码行覆盖非动态类声明
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
如何避免此警告?
这意味着,你不能不重写像扩展中的超类委托方法。 您可以做的方式是将子类声明的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
}
}
因为:
扩展可以添加新的功能,以一个类型,但它们不能覆盖现有的功能。
你有2个办法:
1-添加方法的类范围不扩展
2-内部或添加动态类型,你定义
看到此http你的方法:// stackoverflow.com/questions/41869177/cant-override-uitableviewdatasource-and-uitableviewdelegate –
您通过不覆盖扩展名来避免警告 - 请在类的主体中进行覆盖。比较http://stackoverflow.com/q/38213286/2976878 – Hamish
[重写在Swift扩展中的方法]的可能重复(http://stackoverflow.com/questions/38213286/overriding-methods-in-swift-extensions) – Koraktor