filterContentForSearchText:scope:方法来自哪里?

时间:2014-04-21 14:44:23

标签: ios uisearchdisplaycontroller uisearchbardelegate

最近,我注意到filterContentForSearchText:scope:出现在多个关于如何实现搜索栏的教程中。

但是,我查看了UISearchDisplayDelegate and UISearchBarDelegate的引用。我发现这个filterContentForSearchText:scope:既不是必需的也不是可选的方法。

我想知道filterContentForSearchText:scope:是否只是用于过滤搜索结果的传统方法名称?

1 个答案:

答案 0 :(得分:2)

是的,这只是从UISearchDisplayDelegate方法

调用的常用方法的惯例
- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString;
- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchScope:(NSInteger)searchOption;

当前"Simple UISearchBar with State Restoration" 来自Apple的示例项目使用此约定:

- (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;
}