在更新UITableView的时候,会丢失新的可见行的Missing单元格

我在删除一行时遇到了崩溃。

// 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具有严重的问题,animation插入/更新/删除行时段标头变高度。 只需将高度转换为某个常量并再次尝试。

这实际上意味着删除estimatedSectionHeaderHeight

在我的情况下,当单元格使用自动布局来计算它的高度时,它会崩溃。 所以,唯一有保证的解决scheme是使用手动计算高度。 (真的很伤心..)

删除tableView.dequeueReusableCell中的indexPath

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

在我的情况,我有这个问题只是插入第一行到一个空的部分,所以我试图解决这个问题:

 self.array.append(item) if self.array.count > 1 { self.tableView.beginUpdates() self.tableView.insertRows(at: indexPathes, with: .top) self.tableView.endUpdates() } else { self.tableView.reloadSections([1], with: .fade) } 

我有一个类似的问题。

emrekyvbuild议删除estimatedSectionHeaderHeight但我有一个正面,没有标题,没有页脚的表。

扩大他的想法,并设置estimatedRowHeight为0(=不自动)解决了这个问题。

所以规则是:

更新UITableView时不要估计任何高度。