【发布时间】:2018-09-30 19:16:22
【问题描述】:
我在表格视图中显示了一个自定义对象 [物种] 的列表,该列表按字母顺序排序。表格有一个没有标题的部分,它是一个连续的列表。
我想要实现的是,当用户选择“按国家”对数据进行排序的选项时,执行以下操作:
- 对数组进行排序以找出我需要多少个部分 - “Species.country”
- 创建带有国家标题的部分
- 按字母顺序对国家(部分)进行排序
- 重新加载表格视图以显示部分
- 删除反向操作的部分(对整个列表 A-Z 排序)
过滤/排序时是否可以动态创建部分?你能给我指出正确的方向吗?非常感谢 A.
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 120
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.genusArr.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell: CustomMenuCell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! CustomMenuCell
//genusArr is type of [Species]
let genus = self.genusArr[indexPath.row]
cell.populate(with: genus)
return cell
}
【问题讨论】:
-
请展示您已经尝试过的内容、无效的内容、代码示例等。请阅读How to Ask 和minimal reproducible example 然后edit 您的问题显示最小值 演示问题的代码。
-
您在一篇帖子中有太多问题。这太难回答了。
标签: ios swift uitableview sorting uitableviewsectionheader