Recently, I noticed that filterContentForSearchText:scope:
appeared in multiple tutorials regarding how to implement a search bar.
However, I looked up the references of both UISearchDisplayDelegate and UISearchBarDelegate
. I found this filterContentForSearchText:scope:
is neither a required nor an optional method.
I wondered if filterContentForSearchText:scope:
is just a conventional method name for filtering search results?
Yes, that is only convention for a common method called from the UISearchDisplayDelegate
methods
- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString;
- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchScope:(NSInteger)searchOption;
The current "Simple UISearchBar with State Restoration" sample project from Apple does not use this convention:
- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
NSString *scope;
NSInteger selectedScopeButtonIndex = [self.searchDisplayController.searchBar selectedScopeButtonIndex];
if (selectedScopeButtonIndex > 0)
{
scope = [[APLProduct deviceTypeNames] objectAtIndex:(selectedScopeButtonIndex - 1)];
}
[self updateFilteredContentForProductName:searchString type:scope];
// Return YES to cause the search result table view to be reloaded.
return YES;
}
来源:https://stackoverflow.com/questions/23199678/where-does-filtercontentforsearchtextscope-method-come-from