Ios 带选择器的重写方法具有不兼容的类型-Swift
重写UITableViewDelegate的Ios 带选择器的重写方法具有不兼容的类型-Swift,ios,swift,Ios,Swift,重写UITableViewDelegate的tableView:cellForRowAtIndexPath:会导致以下编译错误: 使用选择器“tableView:cellForRowAtIndexPath:”重写的方法具有不兼容的类型(UITableView!,NSIndexPath!)->UITableViewCell!' 覆盖功能的当前实现是: override func tableView(tableView: UITableView!, cellForRowAtIndexPath ind
tableView:cellForRowAtIndexPath:
会导致以下编译错误:
使用选择器“tableView:cellForRowAtIndexPath:”重写的方法具有不兼容的类型(UITableView!,NSIndexPath!)->UITableViewCell!'
覆盖功能的当前实现是:
override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell!
{
let cell = tableView.dequeueReusableCellWithIdentifier("cellIdent", forIndexPath: indexPath) as UITableViewCell
// Configure the cell...
return cell
}
导致错误的原因以及如何修复错误?删除
隐式可选类型
。签入UITableViewDataSource
对于表视图
,没有可选项,indepath
。在实现协议
方法时,也要删除覆盖
,而无需编写覆盖
替换为以下方法
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
//the error is on the line oboe... Overriding method with selector 'tableView:cellforRowAtIndexPath:'has incompatible type '(TableView, NSIndexpath) -. UITableViewCell!'
{
let cell = tableView.dequeueReusableCellWithIdentifier("cellIdent", forIndexPath: indexPath) as UITableViewCell
// Configure the cell...
return cell
}
试试这个:
重写func tableView(tableView:UITableView,cellForRowAtIndexPath:nsindepath)->UITableView单元格
{
这可能有助于:
尝试删除“覆盖”。如果不起作用,请发布整个课程。