H.E*_*ein 0 uitableview ios swift
我正在尝试使用表视图并在 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
}
Run Code Online (Sandbox Code Playgroud)
问题是您的 IndexPath 参数。
您使用的是类而不是实例。正确的方法是:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cellDish:DishTableViewCell = tableView.dequeueReusableCell(withIdentifier: "cellDish", for: indexPath) as! DishTableViewCell
return cellDish
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
9454 次 |
最近记录: |