Ios Swift tableViewCell保持选中状态
当我在VC中选择一个单元格并转到另一个VC,然后再回到第一个VC时,该单元格仍处于选中状态。我在这里和媒体上找到了一些答案,但都不起作用Ios Swift tableViewCell保持选中状态,ios,swift,uitableview,deselect,Ios,Swift,Uitableview,Deselect,当我在VC中选择一个单元格并转到另一个VC,然后再回到第一个VC时,该单元格仍处于选中状态。我在这里和媒体上找到了一些答案,但都不起作用 我在didSelectRowAt中尝试了这一点,但没有任何意义,因为如果我在方法的开头加上这一点,我将永远无法选择一行: tableView.deselectRow(at: indexPath, animated: false) 我也找到了这个解决方案,但它也不起作用: override func viewWillAppear(_ animated: B
我在
didSelectRowAt
中尝试了这一点,但没有任何意义,因为如果我在方法的开头加上这一点,我将永远无法选择一行:
tableView.deselectRow(at: indexPath, animated: false)
我也找到了这个解决方案,但它也不起作用:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
let selectedRow: IndexPath? = tableView.indexPathForSelectedRow
if let selectedRow = selectedRow {
tableView.deselectRow(at: selectedRow, animated: true)
}
else {
print("no selected rows found")
}
}
上述方法始终打印
未找到选定行
如何保持选中状态?您有一些显示或仅显示选择样式的自定义视图?在tableView中选择单元格后:didSelectRowAtIndexPath:@方法的结尾添加tableView.reloadData()为什么不能在cell.selectionStyle=.none
中使用cellForRowAt
方法。