无法将类型的价值“IndexPath.Type”预期参数类型“IndexPath”

问题描述:

我试图使用表格视图,并在FUNC: cellForRowAt我得到一个错误:Cannot convert value of type 'IndexPath.Type' to expected argument type 'IndexPath'无法将类型的价值“IndexPath.Type”预期参数类型“IndexPath”

我的代码是:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
    let cellDish:DishTableViewCell = tableView.dequeueReusableCell(withIdentifier: "cellDish", for: IndexPath) as! DishTableViewCell  
    return cellDish 
} 
+1

'for:indexPath'。使用参数'indexPath'小写'i'而不是'IndexPath'类型。 – vacawama

+0

谢谢!有用 –

问题是您的IndexPath参数。

您使用的是类而不是实例。正确的方法是:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
    let cellDish:DishTableViewCell = tableView.dequeueReusableCell(withIdentifier: "cellDish", for: indexPath) as! DishTableViewCell  
    return cellDish 
}