I'm using a UINavController together with some UITableViews to display a kind of drill down for some data (e.g. like the Contact App). Works well. The only problem I have is, when I select a cell in the first table view it is highlighted, then the view switches to the next level and then, if I go back to the first level, the cell is still highlighted. So, how can I reset the highlighting when switching back?
我使用UINavController和一些UITableViews来显示一些数据的钻取(例如,联系人应用程序)。工作得很好。我唯一的问题是,当我在第一个表视图中选择一个单元格时,它被高亮显示,然后视图切换到下一个级别,然后,如果我回到第一级,单元格仍然被高亮显示。那么,在切换回来时,如何重置高亮显示?
2 个解决方案
#1
7
In the controller for the table view do:
在控制器中为表视图做:
-(void) viewWillAppear:(BOOL)inAnimated {
NSIndexPath *selected = [self.table indexPathForSelectedRow];
if ( selected ) [self.table deselectRowAtIndexPath:selected animated:NO];
}
Or you can deselect the selected row right in tableView:didSelectRowAtIndexPath:
where you handle pushing the next controller.
或者,您可以在tableView中取消选中所选行的选择:didSelectRowAtIndexPath:您在哪里处理下一个控制器。
#2
5
Another way is to deselect the cell when you select it.
另一种方法是在选择单元格时取消选择。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
#1
7
In the controller for the table view do:
在控制器中为表视图做:
-(void) viewWillAppear:(BOOL)inAnimated {
NSIndexPath *selected = [self.table indexPathForSelectedRow];
if ( selected ) [self.table deselectRowAtIndexPath:selected animated:NO];
}
Or you can deselect the selected row right in tableView:didSelectRowAtIndexPath:
where you handle pushing the next controller.
或者,您可以在tableView中取消选中所选行的选择:didSelectRowAtIndexPath:您在哪里处理下一个控制器。
#2
5
Another way is to deselect the cell when you select it.
另一种方法是在选择单元格时取消选择。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}