无法转换类型' IndexPath.Type'的值预期的参数类型' IndexPath'

时间:2017-10-08 17:46:38

标签: ios swift uitableview

我试图在func中使用表视图: cellForRowAt我收到错误:Cannot convert value of type 'IndexPath.Type' to expected argument type 'IndexPath'

我的代码是:

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

1 个答案:

答案 0 :(得分:2)

问题是您的IndexPath参数。

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

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