I have used following line of code for adding a search bar as a tableHeaderView
:
self.tableView.tableHeaderView = self.searchController.searchBar
But my problem is hiding it like the iOS apps. On the iBooks app's search bar always behind of the Navigation Bar. I don't found any related documentations from the Apple's Documentations.
To hide this bar from the start, you can use setContentOffset
, as demonstrated in this answer:
self.tableView.setContentOffset(CGPoint(x: 0, y: 44), animated: false)
This should hide the search bar from the start.