Override non-dynamic class delaration

≯℡__Kan透↙ 提交于 2019-12-08 16:55:22

问题


With new Xcode 8.3, I get error :

Cannot override a non-dynamic class declaration from an extension

in line of code

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

How I can avoid this warning?


回答1:


which means, you can't not override like super class delegate method in extension. the way you can do is mv extension override method to subclass declare.

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:


because:

Extensions can add new functionality to a type, but they cannot override existing functionality.

you have 2 way:

1- add your method inside the class scope not extension

2- or add dynamic type for your method where you defined



来源:https://stackoverflow.com/questions/43087698/override-non-dynamic-class-delaration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!