[英]Reload tableView section without reloading header section - Swift
[英]Reload only section of tableview when expanding or not - Swift
我设法用单元格折叠该部分,但最后我重新加载了所有表格视图,但我不想要那样。 我想要的是仅在扩展或不扩展(插入/删除)时重新加载该部分。
这是我用来插入或删除我的部分行的方法:
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()
}
}
你应该用 beginUpdates 和 endUpdates 包裹 deleteRows 和 insertRows
tableView.beginUpdates()
tableView.insertRows(at: indexPaths, with: UITableViewRowAnimation.top)
tableView.endUpdates()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.