gpt4 book ai didi

ios - 当搜索栏文本为空时,UISearchController searchResultsController 消失

转载 作者:可可西里 更新时间:2023-11-01 04:45:50 25 4
gpt4 key购买 nike

我有一个 UISearchController,它在点击搜索栏时显示它的 searchResultsController(这是另一个 View Controller )。我使用此 UISearchController 委托(delegate)方法执行此操作:

-(void)presentSearchController:(UISearchController *)searchController {

dispatch_async(dispatch_get_main_queue(), ^{
searchController.searchResultsController.view.hidden = NO;
});
}

但是,只要搜索栏的文本为空,无论是手动删除所有文本还是点击小 x 按钮,searchResultsController View 都会消失,直到我再次开始输入文本。为什么会发生这种情况的任何想法?当 searchbar.text 为空时,是否有其他方法或委托(delegate)方法被触发?

最佳答案

所以在昨天摆弄了一段时间之后,这是我发现最终有效的解决方案。我想我会发布它以防其他人遇到同样的问题!

-(void)presentSearchController:(UISearchController *)searchController {

//forces searchResultsController to appear when searchBar tapped
dispatch_async(dispatch_get_main_queue(), ^{
searchController.searchResultsController.view.hidden = NO;
});
}

-(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {

//Prevents searchController from disappearing
if ([searchText isEqualToString:@""])
{
[self presentSearchController:self.searchController];
}
}

关于ios - 当搜索栏文本为空时,UISearchController searchResultsController 消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30762240/

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