ios - 推送时 UISearchController 不隐藏 View

标签 ios uitableview uisearchbar uisearchdisplaycontroller uisearchcontroller

我正在使用 UISearchController 在 UITableView 中显示搜索栏和结果。我设法正确设置了它,但是当我搜索结果然后选择 TableView 中的一行并将新的 View Controller 推送到导航堆栈时,我希望搜索栏不再可见。但是,当我尝试这样做时,第一个 View Controller 的搜索栏在第二个 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;
}

一种选择是在 didSelectRowAtIndexPath: 中调用 self.searchController setActive:NO] 但没有一种方法可以做到这一点而不会出现令人分心的下拉动画每次从中选择搜索结果时搜索栏。

有没有人遇到同样的问题?有没有办法告诉 UISearchController 在按下时隐藏搜索栏?当我使用 UISearchDisplayController 时它工作正常

最佳答案

将其放入您的调用者 viewDidLoad:

swift :

self.definesPresentationContext = true

objective-C :

self.definesPresentationContext = YES;

这解决了我的问题。

关于ios - 推送时 UISearchController 不隐藏 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30937275/

相关文章:

objective-c - UITableView 没有正确选择

ios - 尽管在属性检查器中启用了分隔线,但它不会显示在自定义 tableView 单元格下

iphone - UISearchDisplayController 与网络获取数据的用法

iOS 构建在编译时失败,出现问题 "failed to find a suitable device for the type SimDeviceType"

iOS 7 UINavigationController 不平衡调用开始/结束外观转换

javascript - getSelection 在 iOS 12 中无法正常工作

ios - 以编程方式实现不滚动的搜索栏

ios - 箭头 anchor 无法在 swift 中正确显示

swift - 更新 TableView 和核心数据

ios - UISearchBar 着色在 iOS7 上不一致