当我在我的 VC 中选择一个单元格并转到另一个 VC,然后再次返回第一个 VC 时,该单元格仍处于选中状态。我在这里和媒体上找到了一些答案,但没有奏效。
我试过了,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")
}
}
上面的方法总是打印 no selected rows found