【问题标题】:UISearchController doesn't hide view when pushedUISearchController 推送时不隐藏视图
【发布时间】:2015-06-19 11:41:32
【问题描述】:

我正在使用 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;
}

一种选择是在didSelectRowAtIndexPath: 内部调用self.searchController setActive:NO],但如果没有每次选择搜索结果时拉下搜索栏的令人分心的动画,就没有办法做到这一点。

有人有同样的问题吗?有没有办法告诉 UISearchController 在推送时隐藏搜索栏?当我使用 UISearchDisplayController 时它工作得很好

【问题讨论】:

标签: ios uitableview uisearchbar uisearchdisplaycontroller uisearchcontroller


【解决方案1】:

把它放在你的调用者的 viewDidLoad:

斯威夫特:

self.definesPresentationContext = true

目标-C:

self.definesPresentationContext = YES;

这解决了我的问题。

【讨论】:

  • 多么晦涩难懂的解决方案。但果然,它奏效了!
  • viewDidLoad 什么?当前或目标控制器。但无论如何在这两种情况下都不起作用。
  • 我不确定还有什么更奇怪的。它对你有用或它对我不起作用的事实。
猜你喜欢
  • 2019-10-27
  • 2012-01-31
  • 2011-11-07
  • 1970-01-01
  • 2016-07-03
  • 1970-01-01
  • 2016-01-03
  • 1970-01-01
  • 2017-01-28
相关资源
最近更新 更多