gpt4 book ai didi

search - UISearchDisplayController : show all results without entering text?

转载 作者:行者123 更新时间:2023-12-02 00:41:08 24 4
gpt4 key购买 nike

我有一个 UISearchDisplayController 用于显示一长串选项供用户选择。我使用 Controller 提供的搜索栏过滤列表。

一切正常,除了我无法显示结果表,除非在搜索栏中输入文本。我想让表格显示我拥有的所有结果,即使搜索栏中没有文本也是如此。目前,当没有文本时,我只有一个暗淡的底层 View 。

请问这可行吗?还是我根本不应该理会 UISearchDisplayController,而只是在我显示的另一个 tableview 中有一个搜索栏,然后将其从堆栈中弹出?

最佳答案

要在出现键盘时用空的 searchBar 立即显示搜索结果,请将以下代码添加到 ViewController:

-(void)searchDisplayControllerDidBeginSearch:(UISearchDisplayController *)controller {
[controller.searchBar.delegate searchBar:controller.searchBar textDidChange:@" "];
}

要在用户输入一些文本然后清除搜索框时保持表格显示结果,请添加:

-(void)searchDisplayController:(UISearchDisplayController *)controller didHideSearchResultsTableView:(UITableView *)tableView {
[controller.searchBar.delegate searchBar:controller.searchBar textDidChange:@" "];
}

不要忘记在 searchDisplayController:shouldReloadTableForSearchString: 中返回 YES

关于search - UISearchDisplayController : show all results without entering text?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2504214/

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