ios - 更新 UITableView 时新可见行的缺失单元格崩溃

标签 ios swift uitableview

我在删除行时遇到崩溃。

// Updating my data model 
....
// apply the updates
self.tableView.beginUpdates()
self.tableView.deleteRows(at: indexPathsToDelete, with: .automatic)
self.tableView.endUpdates()

重现步骤 - 添加行 - 删除行,特别是确保当前屏幕之外有一些行(当删除成功时,这些行将在屏幕中 - 重复直到发生崩溃

它并不总是发生,所以我最好的猜测是它只会在它试图加载的细胞被回收时发生

这是在带有 Xcode 8.0 的 10.0 模拟器中

  *** Assertion failure in -[UITableView _updateWithItems:updateSupport:],
 /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3599.6/UITableView.m:3149
 Missing cell for newly visible row 2
 (null)

cellForRowAt 代码

if isMultipe{
   let cell =  tableView.dequeueReusableCell(withIdentifier: DetailsTableViewCell.defaultIdentifier, for: indexPath) as! DetailsTableViewCell
return cell
    } else {
let cell =  tableView.dequeueReusableCell(withIdentifier: DetailsMultipleTableViewCell.defaultIdentifier, for: indexPath) as! DetailsMultipleTableViewCell
   return cell
}

此处报告了相同的错误:https://forums.developer.apple.com/thread/49676

最佳答案

我遇到了同样的问题,我发现 UITableView 在节标题高度可变时动画插入/更新/删除行时存在严重问题。只需将高度转换为某个常量,然后再试一次。

这实际上意味着删除estimatedSectionHeaderHeight

关于ios - 更新 UITableView 时新可见行的缺失单元格崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40358487/

相关文章:

ios - iBeacon 应用程序 : Custom code when launched from lockscreen

ios - 是否可以隐藏类的继承?

ios - Swift - 如何通过方法调用传递类型?

ios - 当我向 navigationItem 添加更多按钮时,如何使 navigationItem.titleView 居中?

ios - UITextView 的字体为零,但我在 Storyboard 中设置了它

ios - 如何在 Interface builder 的 UIView 中正确添加带有原型(prototype)单元的 UITableView?

ios - 无需开发帐户即可从 Xcode 部署应用程序

ios - 购买完整版时更改应用程序名称

Swift po 导致错误 'Failed to load linked library Metal'

iphone - 当方向改变时如何调整 UITableView 页脚中 UIButton 的大小