问题描述
我正在iOS 8中使用UISearchController,并在视图控制器的viewDidLoad中嵌入以下intializait中的
I am using UISearchController in iOS 8 with the following intializaiton in viewDidLoad of a view controller embedded in a tab controller
_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正确更新等等。
and the search works, the tableview gets updated properly, etc.
但是!
如果我在搜索控制器处于活动状态时切换选项卡(只需点击搜索栏或某些文本)到另一个选项卡,然后返回搜索选项卡,我得到一个只有搜索栏的空白屏幕,如下所示
If I switch tabs while the searchcontroller is active (just tapping the search bar or with some text) to a different tab, and then go back to teh search tab, I get a blank screen with only the search bar, like this
在这种情况下,我搜索以 lar
开头的内容,返回结果并正确显示它们。但如果我切换标签,然后返回搜索标签,我会得到一个这样的空白屏幕。控制器返回其原始状态的唯一方法是,如果我执行 _searchController.active = NO
。但是如果用户希望保持该搜索处于活动状态,我就不能将其停用。
In this case, I search for things that start with lar
, which did return results and displayed them correcly. But if I switch tabs, and return to the search tab I get a blank screen like this. The only way the controller returns to its original state is if I do _searchController.active = NO
. But if the user wants to keep that search active, I can't just deactivate it.
我确信我遗漏了一些东西,但是因为没有太多的东西在UISeachController中,我无法弄清楚是什么导致这个...
I am sure I am missing something, but since there isn't much to do in UISeachController, I can't figure out what is causing this..
推荐答案
尝试self.definesPresentationContext = YES;而不是NO。这是我如何设置我的UISearchController,但我之前没有在UITabBarController中这样做。
Try self.definesPresentationContext = YES; instead of NO. Here is how I setup my UISearchController, but I haven't done it this way in a UITabBarController before.
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
}
这篇关于UISearchController使控制器变黑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!