Peter Pik Peter Pik - 6 months ago 11
Swift Question

UISearchController in navigationBar

I'm trying to use the new UISearchController in my tableViewController.

However I'm a bit confused on how I when I press the searchBar it can move up in the navigationController exactly how it did with the old searchDisplayController?

At the moment it just stay in the tableHeader.

Here is my code:

self.teamSearchController = ({
let controller = UISearchController(searchResultsController: nil)

controller.searchBar.searchBarStyle = UISearchBarStyle.Minimal
controller.dimsBackgroundDuringPresentation = false
controller.searchBar.showsScopeBar = true
self.tableView.tableHeaderView = controller.searchBar

return controller


enter image description here

When I click on searchbar:

enter image description here


You can place the UISearchBar of UISearchController in the navigation bar instead of table header

self.searchController.hidesNavigationBarDuringPresentation = NO;
self.searchController.searchBar.searchBarStyle = UISearchBarStyleMinimal;

// Include the search bar within the navigation bar.
self.navigationItem.titleView = self.searchController.searchBar;

self.definesPresentationContext = YES;