我正在使用 UISearchDisplayController 在 tableview 中显示搜索结果。如果搜索结果为空,我将隐藏 UISearchDisplaycontroller 的 searchResultTableView。它在 iOS 6.0 之前工作正常,但在 iOS 7 中没有。我正在努力寻找一些解决方案,但不幸的是我还没有找到它。我正在使用以下语句来隐藏 searchResultTableView
self.searchDisplayController.searchResultsTableView.hidden=YES;
以下是 iOS 6 和 iOS 7 中的屏幕截图。
编辑:
我正在使用以下 UISearchDisplayController 委托方法
-(BOOL)searchDisplayController:(UISearchDisplayController *)controller
shouldReloadTableForSearchString:(NSString *)searchString
{
[self filterContentForSearchText:searchString
scope:[[self.searchDisplayController.searchBar scopeButtonTitles]
objectAtIndex:[self.searchDisplayController.searchBar
selectedScopeButtonIndex]]];
return YES;
}
-(BOOL)searchDisplayController:(UISearchDisplayController *)controller
shouldReloadTableForSearchScope:(NSInteger)searchOption
{
[self filterContentForSearchText:[self.searchDisplayController.searchBar text]
scope:[[self.searchDisplayController.searchBar scopeButtonTitles]
objectAtIndex:searchOption]];
return YES;
}
-(void)filterContentForSearchText:(NSString *)searchText scope:(NSString *)scope{
[Appdelegate.arrFilteredDrugSummary removeAllObjects];
[Appdelegate.arrFilteredDrugID removeAllObjects];
for (DrugDetails *drug in Appdelegate.arrDrugSummary)
{
NSPredicate *predicate = [NSPredicate predicateWithFormat:
@"(SELF BEGINSWITH [cd] %@)", searchText];
if(![drug.tradeName isEqual:[NSNull null]])
{
[drug.tradeName compare:searchText options:NSCaseInsensitiveSearch];
BOOL resultTradeName;
if((resultTradeName = [predicate evaluateWithObject:drug.tradeName]))
{
if (![Appdelegate.arrFilteredDrugID containsObject:drug.ID])
{
[Appdelegate.arrFilteredDrugSummary addObject:drug];
[Appdelegate.arrFilteredDrugID addObject:drug.ID];
}
}
}
}
if (![Appdelegate.arrFilteredDrugSummary count])
{
[self.btnAddNewDrug setHidden:NO];
self.tblview.hidden=YES;
self.searchDisplayController.searchResultsTableView.hidden = YES;
}
else
{
[self.btnAddNewDrug setHidden:YES];
self.tblview.hidden=NO;
self.searchDisplayController.searchResultsTableView.hidden = NO;
}
[self.searchDisplayController.searchResultsTableView reloadData];
}