2

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?

David Liu
  • 16,374
  • 12
  • 37
  • 38

1 Answers1

2

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;
}
Martin R
  • 529,903
  • 94
  • 1,240
  • 1,382