gpt4 book ai didi

ios - 推送时 UISearchController 不隐藏 View

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

我正在使用 UISearchController 在 UITableView 中显示搜索栏和结果。我设法正确设置了它,但是当我搜索结果然后选择 TableView 中的一行并将新的 View Controller 推送到导航堆栈时,我希望搜索栏不再可见。但是,当我尝试这样做时,第一个 View Controller 的搜索栏在第二个 View Controller 中可见:

    if (self.searchController == nil) {
self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
self.searchController.searchResultsUpdater = self;
self.searchController.dimsBackgroundDuringPresentation = NO;
self.searchController.searchBar.scopeButtonTitles = @[];
self.searchController.searchBar.delegate = self;

self.tableView.tableHeaderView = self.searchController.searchBar;
}

一种选择是在 didSelectRowAtIndexPath: 中调用 self.searchController setActive:NO] 但没有一种方法可以做到这一点而不会出现令人分心的下拉动画每次从中选择搜索结果时搜索栏。

有没有人遇到同样的问题?有没有办法告诉 UISearchController 在按下时隐藏搜索栏?当我使用 UISearchDisplayController 时它工作正常

最佳答案

将其放入您的调用者 viewDidLoad:

swift :

self.definesPresentationContext = true

objective-C :

self.definesPresentationContext = YES;

这解决了我的问题。

关于ios - 推送时 UISearchController 不隐藏 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30937275/

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