Adding a UISearchController to a view without a table

I'm having trouble using the new UISearchController in iOS8. Every example I have found so far uses a search bar as a UITableView header. What will you do when the search bar should appear elsewhere? For example, placing the search bar outside the table to prevent it from scrolling? How to use it with something like UICollectionView?

Am I missing something? It doesn't seem to be that hard.

+6
source share
1 answer

Placing a UISearchBar in the titleView navigation bar, you can prevent it from scrolling when scrolling through the table.

 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 a view controller that manages search results. Ensure that the view manager searchResultsController to the text-based searchResultsController property updates in the UISearchBar when the UISearchController active. That way you can use the UISearchController with a tableview or collectionview view.

+3
source

Source: https://habr.com/ru/post/976574/


All Articles