我目前在didSelectRowAtIndexPath委托方法中做一些工作,并注意到当我稍后回到视图控制器时,我的行仍然保持“选定”状态。
如何在委托方法内取消选择此行?
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//do logic and ... it remains selected in the view?
}
我目前在didSelectRowAtIndexPath委托方法中做一些工作,并注意到当我稍后回到视图控制器时,我的行仍然保持“选定”状态。
如何在委托方法内取消选择此行?
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//do logic and ... it remains selected in the view?
}
[tableView deselectRowAtIndexPath:indexPath animated:YES];
通常在视图控制器再次出现时,您希望取消选择行:
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:YES];
}
这就是 UITableViewController
隐式进行的操作,而在视图控制器再次出现后对取消选择过程进行动画处理可以向用户提供有关他们先前所选单元格的有用提示。
viewWillAppear:
,这样用户就不会短暂地看到所选行。 - doctorBroctor