How to perform a cell deselection when a user returns to a table view?
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 (eg 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).