I’ve seen people doing this differently, I would prefer that when you select an item in UITableView (say in screen A), the item is highlighted(selected), and another screen B is pushed to the navigation stack, then when you go back from screen B to screen A, the previously selected item will be unselected with animation, so what you do is to put:
[self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:YES];
inside:
- (void)viewWillAppear:(BOOL)animated;
and this is what Apple’s sample code does. But I’ve seen a lot of people deselecting the row just after it is selected, inside:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
I know it may be just a personal preference, but I wonder is there any official clarification on this? Deselecting in viewWillAppear: lets users know his/her previously selected item, which is a bonus, but for some custom cell, the selected background/view may not be just solid color, and they may have a UIView added to the cell to represent the selected state, which makes the app inconsistent if some cells are deselected with animation and some are straight away after selected without animation.
Does anyone have any idea?
It’s something that’s up to you, if you are customising your applications UI extensively then you might not want to use this highlight at all. Maybe you have a complex cell and instead of using the cells selection trigger to drill down into a detail view or other, maybe you’ll have a
UIButtoninside you cell.It seems to me that UIKit wants to highlight the cell and retain it’s highlight until you pop the detail view controller, at this point, presumably in
viewWillAppear:, the currently selected cell of theUITableViewis deselected, this allows you to have a very subtle and brief indication of which cell was selected to access where you’ve just come from.Doesn’t sound too interesting said like that however imagine if you exit the app and return some hours later, it’s nice to have this small and as I said very subtle animation.
In the applications I’ve done in the past I’ve tended to not use this so much, or select but deselect immediately, so the user doesn’t see a deselection animation upon returning or going “back” to the list. But that said all my cells in the applications I’m referring to have been very heavily customised.