![](/img/trans.png)
[英]how to set the selected check mark as ticked in tableview cell swift 3.0
[英]How to save and persist selected cell check mark in UITableView using Swift?
在 myscenario 中,我试图将JSON
数据加载到我的tableview
中。 在这里,我在表格视图中使用多个单元格选择。 我需要persist
选定的单元格复选checkmark
。 如果我 go 另一个视图 controller 并返回查看 tableview 选择的复选标记需要显示。
我的代码
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
self.tableView.deselectRow(at: indexPath, animated: true)
let item = searching ? filteredData[indexPath.row] : membersData[indexPath.row]
if selectedRows.contains(indexPath.row) {
tableView.cellForRow(at: indexPath)?.accessoryType = .none
} else {
tableView.cellForRow(at: indexPath)?.accessoryType =
}
}
你似乎已经有一个数组什么的
selectedValues
由于您只是在学习,因此只需将其设为全局或 static。
然后在制作每个单元格时检查它。 真的那么容易
您的代码如下所示:
class YourScreen: TableView whatever .. {
var selectedValues: [something]
}
将其更改为全局:
var selectedValues: [something]
class YourScreen: TableView whatever .. {
}
现在在您的tableView#cellForRowAt
中,只需根据该全局设置它。 所以像
if selectedValues.contains(item) {.accessoryType = .checkmark}
学习如何“持久化数据”。 在计算机中确实需要大量工作,从头开始,然后通过一般数据库 SQL、NoSQL、Firebase 等服务,然后是 Core。 和实时更新。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.