Swift 3: Tableview 数据源方法 "Overriding non-open instance method outside of its defining module" 错误
Swift 3: Tableview datasource methods "Overriding non-open instance method outside of its defining module" error
我在核心框架中有一个 open
BaseViewController
class,它实现了表视图数据源方法。假设我有另一个 class(模块外)ClassA
和 BaseViewController
,因为它是超级 class。当我尝试覆盖 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
class 方法应该可以在模块外访问。我尝试将 tableview 方法访问说明符更改为 public
和不同的组合,但似乎没有任何效果。
BaseViewController 的方法应声明为打开。
这是在参考线程中讨论的。
见
我在核心框架中有一个 open
BaseViewController
class,它实现了表视图数据源方法。假设我有另一个 class(模块外)ClassA
和 BaseViewController
,因为它是超级 class。当我尝试覆盖 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
class 方法应该可以在模块外访问。我尝试将 tableview 方法访问说明符更改为 public
和不同的组合,但似乎没有任何效果。
BaseViewController 的方法应声明为打开。 这是在参考线程中讨论的。
见