要将检查标记保存到tableView中,你可以使用一个数组来保存每个tableView单元格的状态。以下是一个示例解决方法:
var checkmarks = [Bool]()
override func viewDidLoad() {
super.viewDidLoad()
// 初始化checkmarks数组
for _ in 0..
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
// 根据checkmarks数组的值设置checkmark
if checkmarks[indexPath.row] {
cell.accessoryType = .checkmark
} else {
cell.accessoryType = .none
}
// 配置其他单元格属性
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
// 更新checkmarks数组的值
checkmarks[indexPath.row] = !checkmarks[indexPath.row]
// 刷新特定行以显示检查标记的变化
tableView.reloadRows(at: [indexPath], with: .automatic)
}
通过使用这个方法,你可以在tableView中保存和显示检查标记。