UITableView does not automatically deselect the selected row when the table re-appears

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:

    [super viewWillAppear:animated];
    // For some reason the tableview does not do it automatically
    [self.tableView deselectRowAtIndexPath:self.tableView.indexPathForSelectedRow 

Why is this and how to fix it?


When your main ViewController is from type UITableViewController, it has a property clearsSelectionOnViewWillAppear, which is per default YES - so it will clear the selection automatically.

This property is not available for an UITableView, i guess it's because it has no ViewWillAppear method either.

A UIViewController doesn't need this property because it has no UITableView originally.

conclusion: you'll have to implement it by yourself when you do not use a UITableViewController.

Need Your Help

How can I send a PNG of a QR-code in a HTTP response body (with Spark)?

java http png zxing

I want to generate a QR-code image, convert it to PNG and return it as a HTTP response to my client.

iOS possible for draggable hide button on UITabbar?

ios uitabbarcontroller uitabbar

Is it possible to add a custom button ontop of a tabbar which can be used to hide and show the tabbar?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.