I'm having trouble with using the new UISearchController in IOS8. Every example I've found so far uses the search bar as the header view of a UITableView. What do you do when the search bar needs to be displayed somewhere else? For example, placing the searchbar outside the table to prevent it from scrolling? What about using it with something like a UICollectionView?
Am I missing something here? It doesn't seem like this should be that complicated.
Placing the UISearchBar
in the titleView
of the navigation bar, you can prevent it from scrolling when the tableview is scrolled.
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;
UISearchController
relies on searchResultsController
which should be the view controller that manages the results of the search.
Make sure that the view controller pointed to by searchResultsController
property updates based on the text in UISearchBar
when the UISearchController
is active. This way you can use the UISearchController with tableview or collectionview.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With