Search code examples
objective-ciosipad

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.


Solution

  • Simply by calling

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

    in your viewWillAppear: method.