ios – UISearchController使控制器变黑

前端之家收集整理的这篇文章主要介绍了ios – UISearchController使控制器变黑前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在iOS 8中使用UISearchController,在viewDidLoad中具有以下intializaiton,该视图控制器嵌入到选项卡控制器中
  1. _searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
  2.  
  3. _searchBar = _searchController.searchBar;
  4. [_searchController.searchBar sizeToFit];
  5. _searchController.searchBar.delegate = self;
  6. _searchController.searchResultsUpdater = self;
  7. _searchController.dimsBackgroundDuringPresentation = NO;
  8. _searchController.hidesNavigationBarDuringPresentation = NO;
  9. self.definesPresentationContext = NO;
  10. _shopsTable.tableHeaderView = _searchController.searchBar;

我实现了

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

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

但!

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

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

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

解决方法

尝试self.definesPresentationContext = YES;而不是NO.这是我如何设置我的UISearchController,但我没有这样做在UITabBarController之前.
  1. func setupSearchController() {
  2. let resultsController = UIStoryboard(name: "ATPageTableViewController",bundle: nil).instantiateViewControllerWithIdentifier("ATPageTableSearchResultsViewController") as! ATPageTableSearchResultsViewController
  3. searchController = UISearchController(searchResultsController: resultsController)
  4. searchController.delegate = self
  5. resultsController.delegate = self
  6. resultsController.cellIdentifier = ATDataSetItemTableViewCellIdentifier;
  7. resultsController.table = self.table!
  8. searchController.searchBar.sizeToFit()
  9. self.tableView.tableHeaderView = searchController.searchBar
  10. searchController.searchResultsUpdater = self
  11. searchController.searchBar.delegate = self
  12. definesPresentationContext = true
  13.  
  14. }

猜你在找的iOS相关文章