Как программно добавить новый раздел в UITableview?
У меня есть разбиение на страницы, и когда я пытаюсь вызвать insertSections в executeBatchUpdates, он работает нормально в первый раз, но при загрузке второй страницы UITableview не обновляется (нет ошибок, просто не обновляется и не вызывает блок завершения).
private var periods = [PeriodHistoryModel]()
func fetchHistoryWith(models: [PeriodHistoryModel]) {
guard models.count > 0 else {
return
}
let newSectionsCount = models.count - periods.count
let lastPeriod = periods.count - 1 >= 0 ? periods.count - 1 : 0
var newRows: [IndexPath] = [IndexPath]()
var newSections: [IndexSet] = [IndexSet]()
let lastPeriodOldCount = periods.last?.sessions.count ?? 0
let lastPeriodNewCount = models[lastPeriod].sessions.count
let newSessionsCount = lastPeriodNewCount - lastPeriodOldCount
if lastPeriod >= 0 {>
for index in 0..<newSessionsCount {
newRows.append(IndexPath(row: lastPeriodOldCount + index, section: lastPeriod))
}
}
for index in 0..<newSectionsCount {
let newSectionIndex = periods.count + index
newSections.append(IndexSet(integer: newSectionIndex))
for rowIndex in 0..<models[newSectionIndex].sessions.count {
newRows.append(IndexPath(row: rowIndex, section: newSectionIndex))
}
}
periods = models
tableView.performBatchUpdates({
for index in 0..<newSections.count {
tableView.insertSections(newSections[index], with: .none)
}
tableView.insertRows(at: newRows, with: .none)
})
}
reloadData не подходит, нужно делать это гладко