重写UITableViewDelegate的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
}
Run Code Online (Sandbox Code Playgroud)
导致错误的原因是什么?
删除implicit optional type.检查UITableViewDataSource没有可选的tableView,indexPath.还删除,override因为你实现了protocol不需要编写的方法override
替换为以下方法
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
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1278 次 |
| 最近记录: |