OGeek|极客世界-中国程序员成长平台

标题: ios - filterContentForSearchText :scope: method come from? 在哪里 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 09:30
标题: ios - filterContentForSearchText :scope: method come from? 在哪里

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

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

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



Best Answer-推荐答案


是的,这只是从 UISearchDisplayDelegate 方法调用的常用方法的约定

- (BOOL)searchDisplayControllerUISearchDisplayController *)controller shouldReloadTableForSearchStringNSString *)searchString;
- (BOOL)searchDisplayControllerUISearchDisplayController *)controller shouldReloadTableForSearchScopeNSInteger)searchOption;

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

- (BOOL)searchDisplayControllerUISearchDisplayController *)controller shouldReloadTableForSearchStringNSString *)searchString
{
    NSString *scope;

    NSInteger selectedScopeButtonIndex = [self.searchDisplayController.searchBar selectedScopeButtonIndex];
    if (selectedScopeButtonIndex > 0)
    {
        scope = [[APLProduct deviceTypeNames] objectAtIndexselectedScopeButtonIndex - 1)];
    }

    [self updateFilteredContentForProductName:searchString type:scope];

    // Return YES to cause the search result table view to be reloaded.
    return YES;
}

关于ios - filterContentForSearchText :scope: method come from? 在哪里,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23199678/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4