ios - 何时更新 tableView?
问题描述
我正在构建一个待办事项列表应用程序,我在其中使用我的部分标题来显示有关该过程的信息。通过字符串操作,我在其中显示了一些关于 To-do 的值。但是要始终保持最新状态,我只知道reloadData()
命令。但是尝试自动删除行看起来真的很糟糕。
所以我的问题是如何以干净的方式更新标题文本,而不是通过reloadData()
.
这是您将待办事项标记为已完成的地方:
alert.addAction(UIAlertAction(title: "Done", style: .default, handler: { (action) in
if indexPath.section == 0 {
self.goals.remove(at: indexPath.row)
} else {
self.goalsB.remove(at: indexPath.row)
}
self.counter+=1
self.saveDefaults()
tableView.deleteRows(at: [indexPath], with: .automatic)
}))
这就是我的 Header 设置的地方:
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let label = UILabel()
label.textColor = UIColor.white
label.backgroundColor = section == 0 ? UIColor(red: 41 / 255.0, green: 76 / 255.0, blue: 103 / 255.0, alpha: 1.0) : UIColor(red: 235 / 255.0, green: 108 / 255.0, blue: 33 / 255.0, alpha: 0.5)
if section == 0 {
label.text = " \(counter) goals completed / \(goals.count) outstanding"
}
return label
}
解决方案
如果您事先知道必须更新哪个特定部分的标题,则可以使用 TableView.reloadSection() 方法。
推荐阅读
- hybris - Hybris 在 Hana 中创建的 Double 和 BigDecimal 属性的问题
- r - 如何按时间而不是日期对数据集进行子集化?
- mysql - Mysql 中的连接或函数,用于包含一列的所有唯一项和第二列的所有唯一项
- java - 如何使用 api 调用在 Sprinboot 后端传递枚举?
- reactjs - 如何更改输入
当人们打字的时候? - android - 用户为 React-native App 上传 FontFamily
- swiftui - 检测到长按手势并停止时如何运行功能?
- android - 调试和发布 apk 在 React Native 0.63.3 中不起作用
- c# - 如何将字符串数据作为 ZIP 存档上传到 C# 中的 FTP 服务器
- python - mpi4py 在分段错误期间查明错误的等级