更新UITableView时,新建可见行的缺失单元格崩溃 [英] Crash with Missing cell for newly visible row when updating UITableView
问题描述
删除行时遇到崩溃。
// Updating my data model
....
// apply the updates
self.tableView.beginUpdates()
self.tableView.deleteRows(at: indexPathsToDelete, with: .automatic)
self.tableView.endUpdates()
重现
的步骤 - 添加行
- 删除行,特别是确保在当前屏幕之外有一些行(当删除成功时将在屏幕上显示
- 重复直到崩溃发生
Steps to reproduce - Add rows - Delete rows, specifically making sure there's some rows outside the current screen (that will then be in screen when the deletion is successful - Repeat until crash occurs
它并不总是发生这样我最好的猜测是它只会在它试图加载的单元格被回收时发生
It doesn't always happen so my best guess is that it will happen only when the cells it's trying to load get recycled
这是在带有Xcode 8.0的10.0模拟器中
This is in 10.0 simulator with Xcode 8.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的代码
code for 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
the same bug reported here : https://forums.developer.apple.com/thread/49676
推荐答案
我遇到了同样的问题,我发现 UITableView
在插入/更新动画方面存在严重问题/当节标题是高度可变时删除行。只需将高度转换为某个常量并再次尝试。
I had the same problem and I found out that UITableView
has serious problems with animating insert/update/delete rows when section headers are variable height. Just convert the height to some constant and try it again.
这实际上意味着删除 estimatedSectionHeaderHeight
。
This actually means deleting estimatedSectionHeaderHeight
.
这篇关于更新UITableView时,新建可见行的缺失单元格崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!