我需要实现搜索历史记录。所以我想要做的是在尚未输入文本时在搜索显示 Controller 中显示历史记录。
我实现了这个:
-(void)searchDisplayControllerDidBeginSearch:(UISearchDisplayController *)controller{
self.searchDisplayController.searchResultsTableView.hidden=NO;
}
还有这个:
- (void)searchDisplayController:(UISearchDisplayController *)controller didHideSearchResultsTableView:(UITableView *)tableView{
self.searchDisplayController.searchResultsTableView.hidden=NO;
}
使表格始终显示。
我还实现了行数来区分情况:(我还处理了 cellForIndexpath
,但无需在此处显示)
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if ([self.searchDisplayController.searchBar.text isEqualToString:@""]) {
NSArray* d=[DropsAppDelegate getSharedInstance].userData.getLastSearches;
return d.count;
}
return [searchResultPlaces count];
}
但这会造成困惑。该表格显示在半透明屏幕后面,并在退出搜索时变得可见。
而且当我实际输入内容时,屏幕也不会关闭。
我该怎么做才能使 UITableView
始终显示?
我查看了所有答案,但没有任何适用于 iOS7 的答案。
最佳答案
看起来你正在与 UISearchDisplayController
作斗争,它一直有些不怀好意,在 iOS7 上更是如此。
我的建议是不要使用它,而是使用搜索栏来实现您需要的功能。这真的没那么困难,你可以得到你需要的一切委托(delegate)回调,而且你不会与技术作斗争。 UISearchBarDelegate讲述了整个故事。
关于ios - UISearch 显示 Controller 上预加载的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21512804/