Table 查看 cellForRowAtIndexPath 警告

Table View cellForRowAtIndexPath warning

我已将我的代码更新为 swift 3.0 并在以下行收到警告:

func tableView(_ tableView: UITableView, cellForRowAtIndexPath indexPath: IndexPath) -> UITableViewCell {

当我尝试使用@nonobjc 使警告静音或将其设为私有函数时,我尝试了每个建议,table 不再加载。

错误为:

Instance method 'tableView(:cellForRowAtIndexPath:)' nearly matches optional requirement 'tableView(:canFocusRowAt:)' of protocol 'UITableViewDelegate'

有谁知道导致此错误的原因以及如何修复它?

非常感谢!

在 swift 3.0 中,数据源的签名更改为:

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

注意 cellForRowAtIndexPath indexPath: IndexPathcellForRowAt indexPath: IndexPath

之间的区别

我正在使用没有任何警告的新方法,希望这能解决您的问题。

干杯。

只需将实现 UITableViewDataSource 协议的声明添加到 class 定义中,如下所示:

class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {}

我遇到了类似的问题,发现如果去掉tableView前下划线之间的space,从这个

func tableView(_ tableView: ...

至此

func tableView(_tableView: ...

奇怪的是警告消失了...