选中标记自定义表格查看单元格和节标题



当点击自定义节标题时,是否可以允许tableView自动选中节中的所有自定义行单元格?我还没有看到任何涉及这方面的教程,我想知道这是否可能?我该如何跟踪每一行和每一节,以便修改字符串数组中的字符串值,该数组的元素数与表中的行数相同?

在这种情况下(如下(,我只是在单击的单元格上放置一个附件类型,并将所选元素附加到所选项目的列表中。当使用手势处理按下某个东西时,您可以附加列表的所有元素。

这是我的代码:

// MARK: UITableViewDelegate
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
guard let cell = tableView.cellForRow(at: indexPath) else { return }
if cell.accessoryType == .none {
cell.accessoryType = .checkmark
selectedItems.append(items[indexPath.row])
} else {
cell.accessoryType = .none
if let text = cell.textLabel?.text,
let index = selectedItems.firstIndex(where: { $0.name == text}) {
selectedItems.remove(at: index)
} else {
print("Error removing selected item from array.")
}
}
}

希望这在某种程度上有所帮助。当做

最新更新