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