我正在尝试在我的表格视图上实现搜索栏。当用户输入文本时,过滤效果很好。当搜索栏中有文本时,范围按钮也可以工作(它过滤来自文本过滤的结果)。我的问题是当搜索栏范围按钮中没有文本时不起作用。过滤方法成功过滤数组;但是tableview没有更新。我试过了;
searchBar:(UISearchBar *)searchBar selectedScopeButtonIndexDidChange:(NSInteger)selectedScope
但它没有用。我在用着
-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString {
// Tells the table data source to reload when text changes
[self filterContentForSearchText:searchString
scope:[[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:[self.searchDisplayController.searchBar selectedScopeButtonIndex]]];
// Return YES to cause the search result table view to be reloaded.
return YES;
}
-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchScope:(NSInteger)searchOption {
// Tells the table data source to reload when scope bar selection changes
[self filterContentForSearchText:self.searchDisplayController.searchBar.text
scope:[[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:searchOption]];
// Return YES to cause the search result table view to be reloaded.
return YES;
}
用于文本过滤。我也试过重新加载数据,它也没有用。我无法弄清楚为什么 tableview 在文本更改后更新但在范围栏更改后它不更新。