【发布时间】:2015-03-06 19:33:14
【问题描述】:
我正在构建一个使用新 UISearchController 的 iOS 8 应用程序。在与搜索控制器相关的表格视图中,我使用了一个部分索引来让用户从表格的一个部分快速跳转到下一个部分。它工作得很好,但是部分索引与表/搜索控制器上的搜索栏重叠。以前有没有人遇到过这个问题,如果有,你是如何解决的?下面是我如何初始化我的搜索控制器:
self.resultsTableController = [self.storyboard instantiateViewControllerWithIdentifier:[SelectSpecialtySearchResultsTVC storyboardId]];
UINavigationController *searchResultsNavController = [[UINavigationController alloc]initWithRootViewController:self.resultsTableController];
self.searchController = [[UISearchController alloc] initWithSearchResultsController:searchResultsNavController];
self.searchController.searchResultsUpdater = self;
self.searchController.hidesNavigationBarDuringPresentation = NO;
self.searchController.searchBar.barTintColor = [UIColor colorWithHexString:kColorGrayLight];
self.searchController.searchBar.translucent = NO;
self.searchController.searchBar.frame = CGRectMake(self.searchController.searchBar.frame.origin.x, self.searchController.searchBar.frame.origin.y, [self.view bounds].size.width, 44.0);
self.searchController.searchBar.delegate = self;
self.tableView.tableHeaderView = self.searchController.searchBar;
//present the search display controller within the confines of this class's table view
self.definesPresentationContext = YES;
// we want to be the delegate for our filtered table so didSelectRowAtIndexPath is called for both tables
self.resultsTableController.tableView.delegate = self;
self.searchController.delegate = self;
【问题讨论】:
-
我怀疑这与您正在实例化搜索栏并将其添加到表头视图这一事实有关,因此它的作用与任何其他表头一样。您希望搜索栏保持在视图顶部,还是在用户向下滚动表格时消失?
-
搜索栏目前随着用户滚动而消失,我相信这是我的团队想要的行为。
-
在您发表评论之后再考虑一下。如果它可以帮助我摆脱重叠索引,那么让搜索栏保持在滚动的顶部对我来说很好。我正在修补将栏添加为单独的视图(在表格之外),但还没有提出一个成功的解决方案。
标签: ios uitableview uisearchbar uisearchcontroller