UISearchController在推送时不会隐藏视图

时间:2015-06-19 11:41:33

标签: ios uitableview uisearchbar uisearchdisplaycontroller uisearchcontroller

我正在使用UISearchController在UITableView中显示搜索栏和结果。我设法正确设置它,但是当我搜索结果然后选择tableview中的一行,并将新的视图控制器推送到导航堆栈时,我希望搜索栏不再可见。但是,当我尝试这个时,第一个视图控制器中的搜索栏在第二个视图控制器中可见:

    if (self.searchController == nil) {
    self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
    self.searchController.searchResultsUpdater = self;
    self.searchController.dimsBackgroundDuringPresentation = NO;
    self.searchController.searchBar.scopeButtonTitles = @[];
    self.searchController.searchBar.delegate = self;

    self.tableView.tableHeaderView = self.searchController.searchBar;
}

一个选项是在self.searchController setActive:NO]内调用didSelectRowAtIndexPath:,但是如果没有每次从中选择搜索结果时都会关闭搜索栏的分散动画,则无法执行此操作。< / p>

有没有人有同样的问题?有没有办法告诉UISearchController在推送时隐藏搜索栏?我使用UISearchDisplayController

时工作正常

1 个答案:

答案 0 :(得分:35)

将其放入来电者的 viewDidLoad:

夫特:

self.definesPresentationContext = true

目标-C:

self.definesPresentationContext = YES;

这解决了我的问题。

相关问题