不知道你有没有遇到过这种情况,我用的是该函数
func tableView(_ tableView: UITableView,
cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: ReusableCell.self), for: indexPath) as! ReusableCell
cell.reloadAction = {
tableView.reloadRows(at: [IndexPath(row: 0, section: 0)], with: .none)
}
return cell
}
检索可重复使用的单元格。但现在每次我重新加载单元格时,都会再次调用此函数,每次调用它都会返回 2 个不同的单元格。 我在 Storyboard上绘制单元格,因此我无法在代码中多次注册单元格。 如果您遇到过这种情况,请帮助我,我很困惑:( 非常感谢。
最佳答案
您的标识符名称看起来很奇怪(您不需要指定其类型(字符串):这是您在界面构建器 Pane 中设置的类型吗? 我建议您检查标识符名称并尝试使用以下代码:withIdentifier:“myCell”。希望这会有所帮助。
关于ios - dequeueReusableCell(indexPath: IndexPath 的 withIdentifier 标识符 : String,)在每次调用时返回 2 个不同的单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56004206/