Preloading data into the UISearchController when selecting SearchBar

In my application, I use UISearchController (new in iOS 8) to display search results. Is there a way to show the default result set that appears when the user clicks on the searchBar without typing anything else?
I found several questions and answers on this topic, but they all used the old UISearchDisplayController, and I could not get the solutions to work with the UISearchController.

thanks

+6
source share
2 answers
self.searchController.searchBar.text = @"\n"; 

This seems to be a trick. Hacky - but hey, it seems we don't have much work to do.

0
source

I think this method is better, be careful when the searchBar is empty and the preload tableview disappears again.

UISearchBarDelegate

 func searchBar(searchBar: UISearchBar, textDidChange searchText: String) { if searchText.isEmpty { dispatch_async(dispatch_get_main_queue()) { self.searchController.searchResultsController?.view.hidden = false } } } func searchBarTextDidBeginEditing(searchBar: UISearchBar) { dispatch_async(dispatch_get_main_queue()) { self.searchController.searchResultsController?.view.hidden = false } } 

UISearchControllerDelegate

 func willPresentSearchController(searchController: UISearchController) { dispatch_async(dispatch_get_main_queue()) { self.searchController.searchResultsController?.view.hidden = false } } 
0
source

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


All Articles