gpt4 book ai didi

ios - UISearchController + ResultsController - 手动数据重新加载

转载 作者:行者123 更新时间:2023-11-29 01:28:16 26 4
gpt4 key购买 nike

我使用 UISearchController 和子类 UITableViewController 作为结果 Controller 来对 Internet 上的 REST API 执行搜索查询。

我希望用户能够输入查询,按键盘上的“go”,然后在结果 Controller 中显示返回的结果,而不是使用 updateSearchResultsForSearchController 委托(delegate)方法过滤结果。

执行查询后,我可以让结果 Controller 加载我的结果,但是当我要求时, TableView 不会重新加载数据。相反,我必须向下拖动表格 View 才能正确重新加载。

我的问题是 - 有没有办法强制结果 Controller 在执行查询后手动刷新?我尝试调用 [self.searchcontroller.searchresultscontroller.tableVIew reloadData] 但无法正确加载结果数组。

搜索 Controller 设置代码

//Setup search controller
_resultsController = [[RxLookupResultsViewController alloc] init];
_searchController = [[UISearchController alloc] initWithSearchResultsController:_resultsController];
[self.searchController.searchBar sizeToFit];
self.searchController.searchResultsUpdater = self;
self.tableView.tableHeaderView = self.searchController.searchBar;
[self.searchController.searchBar setReturnKeyType:UIReturnKeyGo];

self.resultsController.tableView.delegate = self;
self.searchController.delegate = self;
self.searchController.dimsBackgroundDuringPresentation = YES;
self.searchController.searchBar.delegate = self;
self.searchController.searchBar.tintColor = [UIColor darkTextColor];

//NSArray *scope = @[@"Scope 1", @"Scope 2"];
//self.searchController.searchBar.scopeButtonTitles = scope;
self.searchController.searchBar.showsScopeBar = NO;

self.definesPresentationContext = YES;

根据搜索栏文本执行查询后,我运行以下命令:

_resultsController.filteredCodes = searchResultsDrugNames;
[_resultsController.tableView reloadData];

有什么指点吗?我确信我忽略了一些简单的事情,可以用新的眼光来看待这个问题。

谢谢!

最佳答案

Daniel Z 关于在主线程上调用重新加载的评论是解决方案。忘记了在后台线程上调用查询。

关于ios - UISearchController + ResultsController - 手动数据重新加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33766151/

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