UISearchDisplayController without an immediate search: how can I control the dimming of a TableView?

I implemented UISearchDisplayController using the TableSearch link. My list contains just over 10,000 items, which makes filtering too slow to run on every character the user enters. I managed to limit the search when the user clicks the search button with the following code.

- (void)searchBarSearchButtonClicked:(UISearchBar*)searchBar { [self filterContentForSearchText:[self.searchDisplayController.searchBar text] scope:[self.searchDisplayController.searchBar selectedScopeButtonIndex]]; [self.searchDisplayController.searchResultsTableView reloadData]; } - (BOOL)searchDisplayController:(UISearchDisplayController*)controller shouldReloadTableForSearchString:(NSString*)searchString { return NO; } 

Now my problem is that as soon as the user enters the first character, the dimming of the table view disappears, and I would like it to be darkened until the user clicks the search button. (Or cancels the search.)

+4
source share
1 answer

SearchDisplayController is a black box, so you have no control over when it displays searchResultsTableView (which the first time you press a key in a SearchBar).

You can display a translucent view over the results of the TableView to give the initial dimming look provided by the searchDisplayController function, but searchResultsTableView will still be visible.

 - (BOOL)searchDisplayController:(UISearchDisplayController*)controller shouldReloadTableForSearchString:(NSString*)searchString { // display a translucent view over the searchResultsTableView and // make sure it only created on first key press return NO; } 

Another option is to create your own code.

+3
source

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


All Articles