gpt4 book ai didi

ios - UISearchController 使 Controller 变黑

转载 作者:技术小花猫 更新时间:2023-10-29 10:59:07 27 4
gpt4 key购买 nike

我在 iOS 8 中使用 UISearchController,在选项卡 Controller 中嵌入的 View Controller 的 viewDidLoad 中使用以下初始化

 _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 得到正确更新,等等。

但是!

如果我在搜索 Controller 处于事件状态时将选项卡切换到另一个选项卡(只需点击搜索栏或使用一些文本),然后返回到搜索选项卡,我会得到一个只有搜索栏的空白屏幕,如下所示

enter image description here

在这种情况下,我搜索以 lar 开头的内容,它确实返回了结果并正确显示了它们。但是,如果我切换选项卡并返回到搜索选项卡,我会看到这样的空白屏幕。 Controller 返回其原始状态的唯一方法是执行 _searchController.active = NO。但是,如果用户想要保持该搜索处于事件状态,我不能直接将其停用。

我确定我遗漏了什么,但由于在 UISeachController 中没有太多事情要做,我无法弄清楚是什么原因造成的。

最佳答案

尝试 self.definesPresentationContext = YES;而不是没有。这是我设置 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

}

关于ios - UISearchController 使 Controller 变黑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28675961/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com