ios - filterContentForSearchText :scope: method come from? 在哪里

标签 ios uisearchdisplaycontroller uisearchbardelegate

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

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

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

最佳答案

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

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

相关文章:

ios - 在搜索栏中键入字母时应用程序崩溃

ios - <错误>:CGImageCreateWithImageProvider:无效的图像大小:150 x150。__connection_block_invoke_2中的错误:连接中断

ios - 设置 RootViewController 时的方向问题

ios - 带有原型(prototype)自定义单元格和搜索显示 Controller TableView 的 UITableView Controller

ios - 在 `UISearchbar` 中搜索姓名或号码

ios - 为什么我的 UISearchBar 的框架被 UISearchDisplayController 改变了

ios - 为什么全屏时距离侧面距离的自动约束必须为负数?

ios - iOS 上的标准位置服务耗电

ios - iPad 搜索显示 Controller 从第二个单元格开始显示结果

ios - 搜索 NSString 中的任何字符