ios - UISearch 显示 Controller 上预加载的结果

标签 ios objective-c ios7 uisearchbar uisearchbardisplaycontrol

我需要实现搜索历史记录。所以我想要做的是在尚未输入文本时在搜索显示 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];
}

但这会造成困惑。该表格显示在半透明屏幕后面,并在退出搜索时变得可见。 the history results

而且当我实际输入内容时,屏幕也不会关闭。 我该怎么做才能使 UITableView 始终显示? 我查看了所有答案,但没有任何适用于 iOS7 的答案。

最佳答案

看起来你正在与 UISearchDisplayController 作斗争,它一直有些不怀好意,在 iOS7 上更是如此。

我的建议是不要使用它,而是使用搜索栏来实现您需要的功能。这真的没那么困难,你可以得到你需要的一切委托(delegate)回调,而且你不会与技术作斗争。 UISearchBarDelegate讲述了整个故事。

关于ios - UISearch 显示 Controller 上预加载的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21512804/

相关文章:

swift - FBLogOut : ios how to override calling UIActionSheet While FBLogOut in FBSDKLoginButtion

ios - UIKeyboard 在 iOS7 中不会自动半透明

ios - 无法快速访问 JSON 数组

android - React Native Eject 但仍然能够使用 React Native 代码

iOS sdk - 没有 Popover 的 UIImagePickerController

ios - 发布到服务器时嵌套对象的 RestKit 错误

ios - Thread1 exc_bad_access(代码=2)...帮助我

ios - 如何获取 INFOPLIST_FILE 名称 iOS

iphone - iOS 7 UINavigationbar setTranslucent : NO crashes app

ios - swift - UIAlertController 将用户带回到第一个 ViewController