Where does filterContentForSearchText:scope: method come from?

心不动则不痛 提交于 2020-01-14 02:36:08

问题


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?


回答1:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!