【问题标题】:Where does filterContentForSearchText:scope: method come from?filterContentForSearchText:scope: 方法从何而来?
【发布时间】:2014-06-05 15:39:26
【问题描述】:

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

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

我想知道filterContentForSearchText:scope:是否只是过滤搜索结果的常规方法名称?

【问题讨论】:

    标签: ios uisearchdisplaycontroller uisearchbardelegate


    【解决方案1】:

    是的,这只是从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;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-04
      • 1970-01-01
      • 2016-10-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多