Objective c 强制UISearchController全屏显示搜索结果表

Objective c 强制UISearchController全屏显示搜索结果表,objective-c,ios8,uisearchcontroller,Objective C,Ios8,Uisearchcontroller,我有一个UIViewController,其中包含分段控件和UITableView。 都使用在情节提要中设置的自动布局。以下是我在此处设置的约束的代码版本: H:|-[SegmentedControls]-| H:|[TableView]| V:|-[SegmentedControls]-[TableView]| 我添加了UISearchController和UISearchbar作为表的标题视图。 为了显示搜索结果,我创建了一个新的UITableViewController UITable

我有一个UIViewController,其中包含分段控件和UITableView。 都使用在情节提要中设置的自动布局。以下是我在此处设置的约束的代码版本:

H:|-[SegmentedControls]-| 
H:|[TableView]|
V:|-[SegmentedControls]-[TableView]|
我添加了UISearchController和UISearchbar作为表的标题视图。 为了显示搜索结果,我创建了一个新的UITableViewController

UITableViewController *searchResultsController = [[UITableViewController alloc] initWithStyle:UITableViewStylePlain];
searchResultsController.tableView.dataSource = self;
searchResultsController.tableView.delegate = self;

self.searchController = [[UISearchController alloc] initWithSearchResultsController:searchResultsController];
self.searchController.delegate = self;
self.searchController.searchResultsUpdater = self;
self.searchController.searchBar.frame = CGRectMake(self.searchController.searchBar.frame.origin.x, self.searchController.searchBar.frame.origin.y, self.searchController.searchBar.frame.size.width, 44.0);
self.clientListTable.tableHeaderView = self.searchController.searchBar;
self.searchController.searchBar.scopeButtonTitles = @[@"Active", @"Inactive"];
self.definesPresentationContext = YES;
但后来我遇到了一个问题——当我按下搜索栏时,它会显示动画,但显示的视图只占屏幕的一部分,在顶部和底部显示为灰色的chrome,而不是全屏显示。 显示的视图的大小似乎与tableview的大小相等,tableview承载着搜索栏,在屏幕上垂直居中。 我不知道如何覆盖搜索结果的显示,让它们全屏显示。我试图在显示视图控制器和正在显示的视图控制器上显式设置ModalPresentationStyle,但没有成功。
我有一种感觉,我需要以某种方式覆盖搜索结果的显示控制器,但我不知道从哪里开始,有什么想法吗?

在使用了大约一年的变通方法(手动管理来自UISearchBar的输入,不使用UISearchController)后,我找到了一个解决方案。SearchController在一个新表中显示一个带有结果的表,该表的大小与从中调用它的表的大小相同。因此,由于我的表只是视图的一部分,因此呈现的表也不是全屏的。 我犯的错误是,我确实试图隐藏分段控件,但我没有更新约束(在那个时候,自动布局仍然不是很好)。因此,在观看了今年WWDC关于“自动布局的奥秘”的演讲后,我想出了一个解决方案:

    -(void)willPresentSearchController:(UISearchController *)searchController {

[UIView animateWithDuration:0.5
                      delay:0.0
                    options: UIViewAnimationOptionCurveEaseInOut
                 animations:^(void) {
                     [NSLayoutConstraint deactivateConstraints:@[_constraintToTheSegmentalControls,_constraintToTheTop]];
                     [NSLayoutConstraint activateConstraints:@[_constraintToTheTop]];
                     self.segmentedControls.hidden = YES;
                 }
                 completion:NULL];
}

   -(void)didDismissSearchController:(UISearchController *)searchController {

[UIView animateWithDuration:0.5
                      delay:0.0
                    options: UIViewAnimationOptionCurveEaseInOut
                 animations:^(void) {
                     [NSLayoutConstraint deactivateConstraints:@[_constraintToTheSegmentalControls,_constraintToTheTop]];
                     [NSLayoutConstraint activateConstraints:@[_constraintToTheSegmentalControls]];
                     self.segmentedControls.hidden = NO;
                 }
                 completion:NULL];
}
约束“constraintToTheSegmentalControls”是从表视图顶部到分段控件底部的约束,默认情况下处于活动状态。 约束“constraintToTheTop”是从表视图顶部到顶部布局指南的约束,默认情况下处于非活动状态。 我将它们作为IB引用添加到我的视图控制器中

UITableViewController *searchResultsController = [[UITableViewController alloc] initWithStyle:UITableViewStylePlain];
searchResultsController.tableView.dataSource = self;
searchResultsController.tableView.delegate = self;

self.searchController = [[UISearchController alloc] initWithSearchResultsController:searchResultsController];
self.searchController.delegate = self;
self.searchController.searchResultsUpdater = self;
self.searchController.searchBar.frame = CGRectMake(self.searchController.searchBar.frame.origin.x, self.searchController.searchBar.frame.origin.y, self.searchController.searchBar.frame.size.width, 44.0);
self.clientListTable.tableHeaderView = self.searchController.searchBar;
self.searchController.searchBar.scopeButtonTitles = @[@"Active", @"Inactive"];
self.definesPresentationContext = YES;

动画仍然需要一些调整,但解决方案正在发挥作用。

您看过苹果的UICatalog示例代码了吗?这是我做的第一件事,下一件事是在苹果开发者论坛和苹果开发者支持上提问