ios - 获取一个section中的所有indexPaths
问题描述
在对表格视图数据进行某种排序后,我需要重新加载不包括标题的部分。也就是说我只想重新加载该部分中的所有行。但是经过一段时间的搜索,我没有找到一种简单的方法。
reloadSections(sectionIndex, with: .none)
在这里不起作用,因为它将重新加载整个部分,包括页眉、页脚和所有行。
所以我需要reloadRows(at: [IndexPath], with: UITableViewRowAnimation)
改用。但是如何获取该部分中所有行的整个 indexPaths。
解决方案
您可以在给定部分中使用以下函数获取 IndexPath 数组。
func getAllIndexPathsInSection(section : Int) -> [IndexPath] {
let count = tblList.numberOfRows(inSection: section);
return (0..<count).map { IndexPath(row: $0, section: section) }
}
或者
func getAllIndexPathsInSection(section : Int) -> [IndexPath] {
return tblList.visibleCells.map({tblList.indexPath(for: $0)}).filter({($0?.section)! == section}) as! [IndexPath]
}
推荐阅读
- python - 如何从雅虎财经收集范围内的数据?
- mysql - 向 MYSQL 表中添加多对多数据
- html - 将 megamenu 内容与容器 div 对齐
- python - Telepot 允许的用户/聊天 ID
- r - 在 lme4 中运行 GLMM 时出错:pwrssUpdate 中的错误
- elasticsearch - 如何过滤前 3 名中的匹配项 - elasticsearch?
- python - Django 向导表单和动态表单集创建
- node.js - 如何更改传单中缩放控件的位置(Angular)
- plotly-dash - Dash 数据表:从父 div 继承高度
- python - 从特定行读取 CSV