Swift 表视图cellForRowAtIndexPath警告
我已将代码更新为swift 3.0,并在以下行中收到警告:Swift 表视图cellForRowAtIndexPath警告,swift,uitableview,swift3,Swift,Uitableview,Swift3,我已将代码更新为swift 3.0,并在以下行中收到警告: func tableView(_ tableView: UITableView, cellForRowAtIndexPath indexPath: IndexPath) -> UITableViewCell { 当我尝试使用@nonobjc使警告静音或使其成为私有函数时,表将不再加载 错误内容如下: 实例方法“tableView(:CellForRowatineXpath:)”几乎与协议“UITableViewDelegate”
func tableView(_ tableView: UITableView, cellForRowAtIndexPath indexPath: IndexPath) -> UITableViewCell {
当我尝试使用@nonobjc使警告静音或使其成为私有函数时,表将不再加载
错误内容如下:
实例方法“tableView(:CellForRowatineXpath:)”几乎与协议“UITableViewDelegate”的可选要求“tableView(:canFocusRowAt:)”匹配
有人知道是什么原因导致此错误以及如何修复它吗
非常感谢 在swift 3.0中,数据源的签名更改为:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
请注意cellForRowAtIndexPath:indepath
和cellForRowAtIndexPath:indepath
我使用的新方法没有任何警告,希望这能解决你的问题
干杯。只需在类定义中添加实现UITableViewDataSource协议的声明,如下所示:
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {}
我也遇到了类似的问题,发现如果删除tableView之前的下划线之间的空格
func tableView(_ tableView: ...
对此
func tableView(_tableView: ...
奇怪的是,警告消失了 我还没查过swift3,但真的吗?这种改变毫无意义。。背后有什么原因吗?或者只是为了消除“indexPath”的冗余使用“
消除冗余”
确实是Swift 3中的一个重要主题。我已经使用了该代码并做了一个清理,但它仍然给了我相同的错误:(当我展开错误时,它给出了两个指标:移动”表视图(:cellForRowAt:)此处声明的“将此警告静音的扩展名
&要求”tableView(uu:canFocusRowAt:)(UIKit.UITableViewDelegate)
我认为这可能是因为您在应用程序中没有实现UITableViewDataSourceviewcontroller@MAB你可能是对的。我的UITableViewDataSource是视图控制器外部的一个模型对象,我遇到了相同的错误。为了将其减少为警告,我必须在函数声明中添加以下前缀@objc(tableView:DidSelectRowatineXpath:)内部函数tableView…
。