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

}

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...