用户返回到表格视图时如何执行单元格取消选择? [英] How to perform a cell deselection when a user returns to a table view?

查看:63
本文介绍了用户返回到表格视图时如何执行单元格取消选择?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用UITableView显示单元格列表,当用户选择一个单元格时,将使用以下代码显示一个新视图:

 -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[self.navigationController pushViewController:detailsViewController animation:TRUE];
}

通过使用上面的代码,视图将正确显示,但是当我返回时返回到根表视图,则仍选中该单元格。
在许多sdk示例中,我注意到弹出根视图时将单元格取消选择(具有漂亮的动画),但是在任何示例中我都找不到实现此功能的代码。
我知道我可以使用:

  [tableView deselectRowAtIndexPath:indexPath animation:YES]; 

来实现这一点,但是我很好奇这些示例如何在不使用任何代码的情况下实现的。 / p>

有什么想法吗?

解决方案

UITableViewController viewDidAppear:等中调用 super 时会自动为您处理此问题。因此,最简单的方法要实现这一点,是要继承UITableViewController。如果不能(例如,因为表只是更复杂的视图的一部分),则必须使用 viewDidAppear:方法自己进行操作。 (您也应该刷新滚动条)。


I am using a UITableView to display a list of cells, when the user selects a cell then a new view appears by using the following code:

- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
     [self.navigationController pushViewController: detailsViewController animated: TRUE];
}

By using the code above, the view is displayed correctly, but when I return back to the root table view, then the cell is still selected. I noticed, in many sdk examples, that the cell is deselected (with a nice animation) when the root view is poped pack, but I could not find the code that implemented this feature in any of the examples. I know that I can use:

[tableView deselectRowAtIndexPath:indexPath animated: YES];

to implement this, but I am very curious on how these examples do it without using any code.

Any ideas?

解决方案

UITableViewController automatically handles this for you when you call super in viewDidAppear: etc. So the easiest way to achieve this is to subclass UITableViewController. If you can't (e.g. because the table is just a part of a more complex view), then you'll have to do it yourself in the viewDidAppear: method. (You should also flash the scrollers, too).

这篇关于用户返回到表格视图时如何执行单元格取消选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆