When I push a view after a user has selected a UITableView row, the row gets a blue highlight, and then the new view appears. That's fine. But when I go 'back' the row is still highlighted in blue. Here's my didSelectRowAtIndexPath code.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
SettingsViewController *controller = [[SettingsViewController alloc] initWithNibName:@"SettingsView" bundle:nil];
[[self navigationController] pushViewController:controller animated:YES];
[controller release], controller = nil;
}
What am I doing wrong?
The default behaviour of
UITableViewController
deselects the row when the user returns from the detail view. The response given by Luke is fine, but I want to point out the reason for it:1- If you have your
UITableViewController
like it was when you created it from scratch, you will have all the default behaviours.2- If in the situation 1 you add a
-viewWillAppear
or-viewDidAppear
, then you will be overwriting the standard behaviour. Them, if you want that the row deselects on return, you must say thesuper
explicitly that you'd like it to deselect the row by himself as it always did! To achieve this, as Luke says, you must call[super viewWillAppear:animated]
or[super viewDidAppear:animated]
like this: