I have a UIViewController that manages a UISearchBar and UITableView. I've read that Apple discourage having multiple UIViewControllers manage part of your application, so I did not used UITableViewController to manage the UITableView. Instead, I implemented the UITableViewDelegate
and UITableViewDataSource
protocol in my own UIViewController.
My question is, since I am no longer using UITableViewController, how do I actually change the clearsSelectionOnViewWillAppear
behavior? This property is part of UITableViewController.
Simply by calling
[myTableView deselectRowAtIndexPath:[myTableView indexPathForSelectedRow] animated:YES];
in your viewWillAppear:
method.
Here the Swift code:
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
if let indexPath = tableView.indexPathForSelectedRow() {
tableView.deselectRowAtIndexPath(indexPath, animated: true)
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With