You could try to put it in the header for the first section like this:
func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
return self.searchController.searchBar
}
I had to solve a very similar situation, and this is what I ended up with:
searchController = UISearchController(searchResultsController: nil)
searchController.searchResultsUpdater = self
searchController.dimsBackgroundDuringPresentation = false
searchController.searchBar.delegate = self
searchController.searchBar.sizeToFit()
searchController.searchBar.tintColor = CARBONCOLOR
searchController.hidesNavigationBarDuringPresentation = false
self.definesPresentationContext = true
let search = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Search, target: self, action: "presentSearch")
self.navigationItem.setRightBarButtonItem(search, animated: true)
With this code to present the searchController
func presentSearch()
{
self.navigationController!.presentViewController(searchController, animated: true, completion: nil)
}
This would put a barbutton in the navbar which would present the searchController over the navbar. This is not exactly what I wanted, but turned out to be the simplest way to allow search from any point in the tableview. It also saves a bit of space, which is better. If you don't have a navbar, you can present from self.