最近,我注意到filterContentForSearchText:scope:
出现在多个关于如何实现搜索栏的教程中。
但是,我查找了两者的参考资料UISearchDisplayDelegate and UISearchBarDelegate
。我发现这filterContentForSearchText:scope:
既不是必需的也不是可选的方法。
我想知道是否filterContentForSearchText:scope:
只是过滤搜索结果的常规方法名称?
最近,我注意到filterContentForSearchText:scope:
出现在多个关于如何实现搜索栏的教程中。
但是,我查找了两者的参考资料UISearchDisplayDelegate and UISearchBarDelegate
。我发现这filterContentForSearchText:scope:
既不是必需的也不是可选的方法。
我想知道是否filterContentForSearchText:scope:
只是过滤搜索结果的常规方法名称?
是的,这只是从方法调用的通用方法的UISearchDisplayDelegate
约定
- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString;
- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchScope:(NSInteger)searchOption;
Apple的当前“具有状态恢复的简单 UISearchBar” 示例项目不使用此约定:
- (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;
}