最近,我注意到filterContentForSearchText:scope:
出现在多个关于如何实现搜索栏的教程中。
但是,我查看了UISearchDisplayDelegate and UISearchBarDelegate
的引用。我发现这个filterContentForSearchText:scope:
既不是必需的也不是可选的方法。
我想知道filterContentForSearchText:scope:
是否只是用于过滤搜索结果的传统方法名称?
答案 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;
}