ios - dequeueReusableCell(indexPath: IndexPath 的 withIdentifier 标识符 : String,)在每次调用时返回 2 个不同的单元格

标签 ios swift uitableview reuseidentifier

不知道你有没有遇到过这种情况,我用的是该函数

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/

相关文章:

ios - 将 UICollectionView 添加到导航栏

ios 应用程序不适合 iphone 屏幕

iphone - 我可以从我的服务器获取应用内购买的价格吗?

swift - 避免在 Swift 中连续声明 "if let"

ios - 检查函数在 Swift 中是否可用?

ios - 后台的 Swift 定时器

ios - 如何使用分钟数据过滤特定的一天时间作为 Swift 3 中多个索引中的单个索引存储到数组中

iphone - 删除高度大于其他单元格的单元格时,动画看起来很尴尬

iphone - 如何向 UITableViewCell 添加斜面

ios - UITableView 未声明类型 Cell?