Swift TableView崩溃:“缺less新可见行的单元格”

我在向tableview添加新行时遇到崩溃。 简而言之,崩溃日志说“缺less单元格为新的可见行3”。

再生产
1.将N个对象添加到数据源
2.手动添加相同数量的单元格到tableview
3.使用beginUpdates – endUpdates重新加载和animation

已知的问题
这个崩溃已经在苹果 问题上讨论过了。 他们对这个问题的解决scheme(不使用估计的细胞高度)不适合我,因为我需要2个不同高度的细胞。

我的tableview是由2个不同的单元格类组成的。 两者都有自己的标准高度,configuration如下:

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { if indexPath.row % (straightsetLogs.count + 1) == 0 { return 44 } else { return tableView.rowHeight } } func numberOfSections(in tableView: UITableView) -> Int { return 1 } func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { // (exerciseSets.count / straightsetLogs.count) = amount of (super)sets // (straightsetLogs.count + 1) = amount of cells needed for 1 (super)set return (exerciseSets.count / straightsetLogs.count) * (straightsetLogs.count + 1) } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { // Headercell: 1 headercell for every (super)set if indexPath.row % (straightsetLogs.count + 1) == 0 { // Create header cells once for every set let headerCell = tableView.dequeueReusableCell(withIdentifier: CellID.setHeaderCell, for: indexPath) as! SetHeaderTableViewCell return configureHeaderCell(headerCell, forIndexPath: indexPath, totalCellsPerSet: straightsetLogs.count + 1) } else { // Create picker cells for rest of rows let pickerCell = tableView.dequeueReusableCell(withIdentifier: CellID.setPickerCell, for: indexPath) as! SetPickerTableViewCell // Configure according to set and movement return configurePickerCell(pickerCell, forIndexPath: indexPath, totalCellsPerSet: straightsetLogs.count + 1) } } 

在故事板中,我已经configuration了tableview本身的行高为260.0,对于标题单元格,我已经检查了自定义行高度框并将其设置为44.0。

当前状态
用于确定索引path的正确单元格的代码工作和崩溃可以通过删除indexPath代码行的高度来解决。 但是,我最终所有的细胞是260.0高度。

目标
我需要44.0高度的标题单元格和260.0高度的选取单元格,而不会遇到此崩溃。