我正在尝试在我的表视图上实现搜索栏.当用户输入文本时,过滤效果很好.当搜索栏中有文本时,范围按钮也可以工作(它通过文本过滤过滤结果).我的问题是当搜索栏中没有文字时,范围按钮不起作用.过滤方法成功过滤数组;但是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更新但在范围栏更改后它没有更新.
解决方法
我解决了这个问题.我不再使用searchDisplayController,而是使用textDidChange和selectedScopeButtonIndexDidChange.而不是使用两个表视图(normal和self.searchDisplayController.searchResultsTableView)我正在使用单表视图并且我更改其数据源,现在看来这解决了我的问题.但仍然无法弄清楚为什么应该调用divoadTableForSearchScope:不调用cellForRowAtIndexPath:并更新我的表视图
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。