【发布时间】:2017-08-18 19:13:44
【问题描述】:
我在核心框架中有一个 open BaseViewController 类,它实现了 tableview 数据源方法。假设我有另一个类(模块外)ClassA 和 BaseViewController,因为它是超类。当我尝试覆盖 tableview 数据源方法时,它会抛出此错误Overriding non-open instance method outside of its defining module。
BaseViewController 看起来像这样
open class BaseViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
...
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 0
}
public func numberOfSections(in tableView: UITableView) -> Int {
return 0
}
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
return UITableViewCell()
}
}
A类
import CustomCoreFramework
class ClassA : BaseViewController {
// throws an error
public override func numberOfSections(in tableView: UITableView) -> Int {
return tableViewListItems.count
}
}
我想open 类方法应该可以在模块外部访问。我尝试将 tableview 方法访问说明符更改为 public 和不同的组合,但似乎没有任何效果。
【问题讨论】:
-
可能是因为方法被标记为 public 尝试删除 public 一次并检查,虽然之前没有尝试过,但不确定。
-
你必须从 UIViewController 而不是
UITableViewDelegate继承BaseViewController——顾名思义—— -
是否应该将 BaseViewController 的方法声明为打开?
-
@vadian 是的,我正在这样做,只是忘了把它放在帖子里。我已经更新了帖子。请检查。
标签: ios swift uitableview inheritance ios-frameworks