微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ios – UISearchController使控制器变黑

我在iOS 8中使用UISearchController,在viewDidLoad中具有以下intializaiton,该视图控制器嵌入到选项卡控制器中
_searchController = [[UISearchController alloc] initWithSearchResultsController:nil];

    _searchBar = _searchController.searchBar;
    [_searchController.searchBar sizetoFit];
    _searchController.searchBar.delegate = self;
   _searchController.searchResultsUpdater = self;
    _searchController.dimsBackgroundDuringPresentation = NO;
    _searchController.hidesNavigationBarDuringPresentation  = NO;
    self.definesPresentationContext = NO;
    _shopsTable.tableHeaderView = _searchController.searchBar;

我实现了

– (void)updateSearchResultsForSearchController:(UISearchController *)searchController和(void)filterContentForSearchText:(Nsstring *)searchText

搜索工作,tableview得到正确更新等.

但!

如果我在搜索控制器处于活动状态(只需点击搜索栏或某些文本)时切换标签页,然后返回到搜索选项卡,我将只显示一个空白屏幕,如同这样

在这种情况下,我搜索从lar开始的事情,它返回结果并显示它们.但是如果我切换选项卡,并返回到搜索选项卡,我会得到一个这样的空白屏幕.控制器返回到原始状态的唯一方法是,如果我执行_searchController.active =否.但是,如果用户希望保持搜索活动,我不能仅仅停用它.

我相信我错过了一些东西,但是由于UISeachController没有太多的工作,所以我无法弄明白是什么原因造成的.

解决方法

尝试self.definesPresentationContext = YES;而不是NO.这是我如何设置我的UISearchController,但我没有这样做在UITabBarController之前.
func setupSearchController() {
    let resultsController = UIStoryboard(name: "ATPageTableViewController",bundle: nil).instantiateViewControllerWithIdentifier("ATPageTableSearchResultsViewController") as! ATPageTableSearchResultsViewController
    searchController = UISearchController(searchResultsController: resultsController)
    searchController.delegate = self
    resultsController.delegate = self
    resultsController.cellIdentifier = ATDataSetItemTableViewCellIdentifier;
    resultsController.table = self.table!
    searchController.searchBar.sizetoFit()
    self.tableView.tableHeaderView = searchController.searchBar
    searchController.searchResultsUpdater = self
    searchController.searchBar.delegate = self
    definesPresentationContext = true

}

原文地址:https://www.jb51.cc/iOS/329110.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐