2

我需要实现搜索历史。所以我想要做的是在尚未输入文本时在搜索显示控制器中显示历史记录。

我实现了这个:

-(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 没有任何作用。

4

1 回答 1

2

看起来你在打架UISearchDisplayController,这一直有点不情愿,在 iOS7 上更是如此。

我的建议是不要使用它,而是使用搜索栏实现您需要的功能。这真的没那么难,你得到了你需要的一切的委托回调,而且你不用对抗技术。UISearchBarDelegate讲述了整个故事。

于 2014-02-04T20:13:07.370 回答