I made it work to to collapse the section with cells but at the end i reload all the tableview and i don't want that. What i want is to reload only the section when it expands or not (inser/delete).
Here is the method which i use to insert or delete the rows of my section:
func settingsViewTapped(view: SettingsCellView, section: Int) {
var indexPaths = [IndexPath]()
for row in self.settingsTrainings[section].workouts.indices {
let indexPath = IndexPath(row: row, section: section)
indexPaths.append(indexPath)
}
let isExpanded = self.settingsTrainings[section].isExpanded
self.settingsTrainings[section].isExpanded = !isExpanded
if isExpanded {
tableView.deleteRows(at: indexPaths, with: .none)
tableView.reloadData()
} else {
tableView.insertRows(at: indexPaths, with: .none)
tableView.reloadData()
}
}