我试图在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
}
答案 0 :(得分:2)
问题是您的IndexPath参数。
您正在使用该类而不是实例。正确的方法是:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cellDish:DishTableViewCell = tableView.dequeueReusableCell(withIdentifier: "cellDish", for: indexPath) as! DishTableViewCell
return cellDish
}