Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change clearsSelectionOnViewWillAppear when not using UITableViewController?

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.

like image 922
pixelfreak Avatar asked Jul 13 '11 21:07

pixelfreak


2 Answers

Simply by calling

[myTableView deselectRowAtIndexPath:[myTableView indexPathForSelectedRow] animated:YES];

in your viewWillAppear: method.

like image 59
omz Avatar answered Sep 20 '22 16:09

omz


Here the Swift code:

override func viewWillAppear(animated: Bool) {
    super.viewWillAppear(animated)
    if let indexPath = tableView.indexPathForSelectedRow() {
        tableView.deselectRowAtIndexPath(indexPath, animated: true)
    }
}
like image 35
Darko Avatar answered Sep 21 '22 16:09

Darko