Normally a selected row in a UITableView gets deselected with an animation when the user pops back from the detail view.
However, in my case where I have a UITableView embedded in a UIViewController I have to do it manually in viewWillAppear like so:
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
// For some reason the tableview does not do it automatically
[self.tableView deselectRowAtIndexPath:self.tableView.indexPathForSelectedRow
animated:YES];
}
Why is this and how to fix it?
When your main ViewController is from type UITableViewController, it has a property
clearsSelectionOnViewWillAppear, which is per defaultYES– so it will clear the selection automatically.This property is not available for an UITableView, i guess it’s because it has no
ViewWillAppearmethod either.A UIViewController doesn’t need this property because it has no
UITableVieworiginally.conclusion: you’ll have to implement it by yourself when you do not use a
UITableViewController.