我不断收到错误消息:
无法将类型“ Int”的值转换为预期的元素类型 'IndexPath'
在线self.tableView.reloadRows(at: [selectedIndexPath], with: .none)
代码:
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let selectedIndexPath = indexPath.row
myModels[selectedIndexPath].isSelected = true
self.tableView.reloadRows(at: [selectedIndexPath], with: .none)
}
如何改善?
答案 0 :(得分:0)
因此,reloadRows(at:
需要一个数组,其中包含IndexPath
作为第一个参数,即:[IndexPath]
。您将row
的{{1}}中的IndexPath
放入一个数组中,即:Int
。
在我看来,您似乎只是在尝试重新加载选定的单元格,因此您应该替换此:
[Int]
与此:
self.tableView.reloadRows(at: [selectedIndexPath], with: .none)
因此您的整个didSelectRowAtIndexPath函数应如下所示:
tableView.reloadRows(at: [indexPath], with: .none)