我正在将JSON
数据加载到Tableview中。我的tableview允许多选checkmark
选项。现在,我无法store
选中单元格复选标记。怎么做?
NOTE:
JSON数据数组的数量将来可能会增加
我的Tableview代码
func tableView(_ tableView: UITableView,cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell:TeamlistCustomCell = self.tableView.dequeueReusableCell(withIdentifier: cellReuseIdentifier) as! TeamlistCustomCell
let textForRow = searching ? filteredData[indexPath.row] : membersData[indexPath.row]
cell.name.text = textForRow.firstname
return cell
}
func tableView(_ tableView: UITableView,didSelectRowAt indexPath: IndexPath) {
self.tableView.deselectRow(at: indexPath,animated: true)
let item = searching ? filteredData[indexPath.row] : membersData[indexPath.row]
if selectedValues.contains(item) { //deselect
selectedRows.remove(at: indexPath.row)
tableView.cellForRow(at: indexPath)?.accessorytype = .none
selectedValues.remove(item)
} else {
selectedRows.append(indexPath.row) //select
tableView.cellForRow(at: indexPath)?.accessorytype = .checkmark
selectedValues.insert(item)
}
// Selected Row Index Store
UserDefaults.standard.set(selectedRows,forKey: "SelectedIndexes")
}