I've been stumped by this for a while...
When you tap the cell of a contact in Apple's Phone app for the iPhone (entering the view with contact details) and tap back to the previous view, there is a brief animation (fading from blue to white) showing the deselection of the cell. This is the behavior with all table views in Apple's own apps, and also the recommended behavior according to their Human Interface Guidelines.
However, in my own project I've been having trouble replicating this behavior. None of the cells in my UITableView
are selected when I return to it from a detail view.
I looked through the CoreDataBooks sample code in Apple's documentation, which has the desired cell deselection behavior, and it seems like the table view gets the behavior "automatically" (without any specific implementation).
I've also tried implementing the solutions in these very similar questions:
What deselect selected cell when navigationController pops a view?
iPhone UITableView cells stay selected
UITableView doesn't keep row selected upon return
But I always get the same result -- none of the cells in the UITableView
are selected when I return to it. (Even after adding [tableView deselectRowAtIndexPath:[tableView indexPathForSelectedRow] animated:animated];
in the view controller's -viewWillAppear:
method.)
It was also suggested in the comments of one question that having [[self tableView] reloadData];
in -viewWillAppear:
may be causing the cells not to stay selected. But CoreDataBooks does the same thing and still has the desired behavior (seemingly) without any specific code.
Any suggestions on how to resolve the problem? Thanks in advance.
On a side note, I don't quite understand why the code to deselect the cell should be implemented in -viewWillAppear:
(rather than -viewDidAppear:
). Wouldn't that cause everything to happen before the table view is displayed on screen? This is probably just due to lack of proper understanding of a view's life cycle on my part, but any clarifications would be nice. Thanks again.