Использование фальцовки ячеек фреймворка вместе с PaginatedTableView фреймворка, который, кажется, работает нормально с 20-40 строками.когда я касаюсь ячейки, она открывается / закрывается без каких-либо проблем, но при прокрутке данных происходит -> нажатие на ячейку выбрасывает ниже ошибкив разделе 0. Количество строк, содержащихся в существующем разделе после обновления (80), должно быть равно числу строк, содержащихся в этом разделе до обновления (60), плюс или минус количество строк, вставленных или удаленных из этогораздел (0 вставлено, 0 удалено) и плюс или минус количество строк, перемещенных в или из этого раздела (0 перемещено, 0 перемещено).
Я устанавливаю значение для высоты ячейки при загрузкеданные из API
self.cellHeights = (0..<self.myNewsList.count).map{ _ in C.CellHeight.close }
var cellHeights: [CGFloat] = []
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = tableView.dequeueReusableCell(withIdentifier: "TableViewCell", for: indexPath) as? TableViewCell else {
fatalError("The dequeued cell is not an instance of TableViewCell.")
}
let durations: [TimeInterval] = [0.26, 0.2, 0.2]
cell.durationsForExpandedState = durations
cell.durationsForCollapsedState = durations
return cell
}
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}`
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
guard case let cell as FoldingCell = tableView.cellForRow(at: indexPath) else {return}
if cell.isAnimating() {
return
}
var duration = 0.0
let cellIsCollapsed = self.cellHeights[indexPath.row] == C.CellHeight.close
if cellIsCollapsed {
self.cellHeights[indexPath.row] = C.CellHeight.open
cell.unfold(true, animated: true, completion: nil)
duration = 0.5
} else {
self.cellHeights[indexPath.row] = C.CellHeight.close
cell.unfold(false, animated: true, completion: nil)
duration = 0.8
}
UIView.animate(withDuration: duration, delay: 5, options: .curveEaseOut, animations: { () -> Void in
tableView.beginUpdates()
tableView.endUpdates()
if cell.frame.maxY > tableView.frame.maxY {
tableView.scrollToRow(at: indexPath, at: UITableView.ScrollPosition.bottom, animated: true)
}
}, completion: nil)
}
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
guard case let cell as FoldingCell = cell else {
return
}
cell.backgroundColor = .clear
if cellHeights[indexPath.row] == C.CellHeight.close{
cell.unfold(false, animated: false, completion: nil)
} else {
cell.unfold(true, animated: false, completion: nil)
}
}
Я думаю, при нажатии didSelectRowAt
tableView.beginUpdates()
tableView.endUpdates()
получить ошибку 'Неверное обновление: недопустимое количество строк в разделе 0. '