Я реализую сворачиваемые заголовки разделов в UITableViewController.
Вот как я определяю, сколько строк показывать на раздел:
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
return self.sections[section].isCollapsed ? 0 : self.sections[section].items.count
}
Существует структура, содержащая информацию разделас bool для 'isCollapsed'.
Вот как я переключаю их состояния:
private func getSectionsNeedReload(_ section: Int) -> [Int]
{
var sectionsToReload: [Int] = [section]
let toggleSelectedSection = !sections[section].isCollapsed
// Toggle collapse
self.sections[section].isCollapsed = toggleSelectedSection
if self.previouslyOpenSection != -1 && section != self.previouslyOpenSection
{
self.sections[self.previouslyOpenSection].isCollapsed = !self.sections[self.previouslyOpenSection].isCollapsed
sectionsToReload.append(self.previouslyOpenSection)
self.previouslyOpenSection = section
}
else if section == self.previouslyOpenSection
{
self.previouslyOpenSection = -1
}
else
{
self.previouslyOpenSection = section
}
return sectionsToReload
}
internal func toggleSection(_ header: CollapsibleTableViewHeader, section: Int)
{
let sectionsNeedReload = getSectionsNeedReload(section)
self.tableView.beginUpdates()
self.tableView.reloadSections(IndexSet(sectionsNeedReload), with: .automatic)
self.tableView.endUpdates()
}
Все работает и анимируется красиво, однако в консоли при свертывании расширенного раздела яполучить это [Утвердить]:
[Assert] Unable to determine new global row index for preReloadFirstVisibleRow (0)
Это происходит независимо от того, является ли это тот же открытый раздел, закрытие (свертывание), или если я открываю другой раздел и «автоматически закрываю» ранее открытый раздел.
Я ничего не делаю с данными;это постоянно.
Может ли кто-нибудь помочь объяснить, чего не хватает? Спасибо