views:

112

answers:

2

Hi,

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?

Thanks for your help.

Regards Matthias

+4  A: 

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.

drawnonward
Thanks. Works perfect.
Matthias
The recommended way is to do this in viewWillAppear: like you suggest. This gives the user a visual reminder of which cell they came from. Note that if you inherit from UITableViewController you get this behaviour for free. Another thing UITableViewController does which you should also do is call [tableView flashScrollIndicators] in viewDidAppear: so the user is also given a visual cue if the table view has more items than can be displayed on the screen.
Mike Weller
+3  A: 

Another way is to deselect the cell when you select it.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
zonble
+1. This is how most table view apps behave and is the behavior users will probably expect more often than not.
Alex Reynolds