UISearchController doesn't hide view when pushed

℡╲_俬逩灬. 提交于 2019-12-21 03:41:04

问题


I am using UISearchController to display a search bar and results within a UITableView. I managed to set it up correctly, but when I search the results and then select one of the rows in the tableview, and push a new view controller to the navigation stack, I would expect the search bar to not be visible anymore. However, when I try this, the search bar from the first view controller is visible in the 2nd view controller:

    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;
}

One option is to call self.searchController setActive:NO] inside of didSelectRowAtIndexPath: but there isn't a way to do this without the distracting animation of bringing down the search bar each time the search results are selected from.

Does anyone have the same problem? Is there a way to tell UISearchController to hide the search bar when pushed? It worked fine when I was using UISearchDisplayController


回答1:


Put this in your caller's viewDidLoad:

Swift:

self.definesPresentationContext = true

Objective-C:

self.definesPresentationContext = YES;

This solved the problem for me.



来源:https://stackoverflow.com/questions/30937275/uisearchcontroller-doesnt-hide-view-when-pushed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!