首页 > 解决方案 > 如何使用 Swift 在 UITableView 中保存和保留选定的单元格复选标记?

问题描述

在 myscenario 中,我试图将JSON数据加载到我的tableview. 在这里,我在表格视图中使用多个单元格选择。我需要persist选择单元格checkmark。如果我去另一个视图控制器并回来查看 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 = 
    }
}

标签: iosswiftuitableview

解决方案


推荐阅读