[英]UITableView reselects row when scrolling
我有一个带有静态单元格的 tableView。 modalCell(见截图)有一个视图控制器, tableViewController
以模态方式呈现。 如果我关闭模态视图,单元格将被取消选择。 但是,当我将单元格滚动出屏幕并返回以使其再次出现时,该单元格再次被选中。 我在一个新的示例项目中重现了这种行为。
我在ViewController
代码如下所示:
class ViewController: UITableViewController {
@IBOutlet weak var modalCell: UITableViewCell!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if let cell = tableView.cellForRow(at: indexPath), cell == modalCell {
modalCell.setSelected(false, animated: true)
}
}
}
在屏幕录制中,您可以看到单元格正确取消选择。 但是,如果我滚动,则会再次选择该单元格。 任何想法为什么?
只需在表格视图中取消选择单元格
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.