вот
func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if tableViewData[indexPath.section].opened == true {
tableViewData[indexPath.section].opened = false
let section = IndexSet.init(integer: indexPath.section)
tableView.reloadSections(section, with: .automatic)
} else {
tableViewData[indexPath.section].opened = true
let section = IndexSet.init(integer: indexPath.section)
tableView.reloadSections(section, with: .automatic)
}
}
}