UITableViewCell's seleced and deselect check and uncheck

First of all, let’s start with a problem I encountered, an App based on NavigationBar, at the beginning I have a UITableViewController, in which each UITableViewCell will push another ViewController after clicking, and every time the Cell is clicked, the Cell will be selected, when When returning from the push ViewController, the selected Cell will be automatically deselected (animated). Later, for some reasons, I changed this UITableViewController to UIViewController, and then a problem occurred: every time I returned to the TableView, the previously selected Cell could not be automatically unselected. After searching, I found that:

UITableViewController has a property of clearsSelectionOnViewWillAppear,

And when UITableViewController is changed to UIViewController, this property naturally does not exist, so we have to manually add the function of unchecking, the method is very simple, add in the viewWillAppear method:

[self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated :YES];

That's it, it is estimated that UITableViewController also uses a similar method to achieve the function of unchecking.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326863610&siteId=291194637