iOS7 searchDisplayController 隐藏 tableview 索引

标签 ios ios7 tableview

有一个带索引的 TableView 。它们在初始加载时可见。

我还有一个 searchDisplayController

当我使用 searchDisplayController 然后取消它时,突然隐藏了原始 tableview 上的索引。

我在 iOS 6 上从来没有遇到过这个问题。

这是我在 iOS 6 上运行的代码:

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView2 {

 if (self.searchDisplayController.active)
    return nil;

else
    return self.indices;
}

我已经试过了,但没有成功:

- (void)searchDisplayControllerDidEndSearch:(UISearchDisplayController *)controller {
    [self.tableViewOriginal reloadSectionIndexTitles];
}

- (void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller {
    [self.tableViewOriginal reloadSectionIndexTitles];
}

更新:

为了添加 tableView,我使用了 Storyboard并将其与 IBOutlet 连接。 searchBar 和 searchDisplayController 以编程方式添加到 viewDidLoad 中:

  self.searchBar = [[UISearchBar alloc]initWithFrame:CGRectMake(0, 0, 290, 44)]; 
  self.searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:self.searchBar contentsController:self];

如果 cellForRowAtIndexPath,我然后将搜索栏添加到表格单元格

 [cell addSubview:self.searchBar];

最佳答案

您的设置的一个可能问题是您将搜索栏放在表格 View 单元格中。

一个更标准(也更简单)的方法是让搜索栏成为表格 View 的 headerView

self.tableView.headerView = self.searchBar;

只需在设置搜索显示 Controller 后执行一次即可。

关于iOS7 searchDisplayController 隐藏 tableview 索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23696855/

相关文章:

iphone - 更改 TableView 上 UISearchBar 的宽度

ios - 用户滚动时如何停止视频

ios - xib 中的 UINavigationController 不显示

ios - UITableView 中自定义单元格的动态高度

iOS 7 UINavigationBar Retina 图像大小

ios - 在IOS7中打开应用程序时出现白屏

ios - 如何更改分组的 UITableView header 的高度?

ios - 以编程方式更改 UIButton 文本并打开一个 url

ios - 如何通过 interfacebuilder 使用精确的十六进制设置 View 的背景颜色?

ios7 - 需要在 Swift 中将 NSMutableData 转换为 CConstPointer