如何在用户返回视图控制器时取消选择uitableview单元格 [英] How to unselect a uitableview cell when the user returns to the view controller
本文介绍了如何在用户返回视图控制器时取消选择uitableview单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当用户选择它时,我会突出显示一个uitableview单元格,然后将其推送到详细视图。当他们返回到桌面视图控制器时,我希望单元格不被突出显示。
I have a uitableview cell highlighted when a user selects it and then is pushed to a detail view. I would like the cell to be unhighlighted when they return to the table view view controller.
我将如何完成此操作?
我在viewWillAppear中猜测 [cell.textLabel setHighlighted:NO];
,但如果我把它放在那里,则单元格是未声明的。
I'm guessing [cell.textLabel setHighlighted:NO];
in viewWillAppear, but cell is undeclared if I put it there.
感谢您的帮助
推荐答案
如果您使用 UITableViewController
子类然后只设置属性
If you using UITableViewController
subclass then just set property
self.clearsSelectionOnViewWillAppear = YES;
其他在viewDidAppear上只需致电
else on viewDidAppear just call
NSIndexPath *indexPath = self.tableView.indexPathForSelectedRow;
if (indexPath) {
[self.tableView deselectRowAtIndexPath:indexPath animated:animated];
}
// MARK: - Swift 3
if let indexPath = tableView.indexPathForSelectedRow {
tableView.deselectRow(at: indexPath, animated: true)
}
这篇关于如何在用户返回视图控制器时取消选择uitableview单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文