我修改了Apple的示例iOS项目TableSearch的代码,以便通过解析其内容来使用它来搜索Web服务.我使用SearchDisplayController的SearchBar执行搜索时,除了一个丑陋的细节之外,我所实现的一切都很好.我已经改变了SearchDisplayController的行为,以便在点击"搜索"按钮时首先调用我的搜索功能.
问题是当搜索迭代(在NSOperationQueue的后台执行)完成时,(searchDisultsTableView)(searchDisplayController)不会自动显示或未分配结果内容.如果您随后更改SearchBar的文本或点击触摸搜索字段时出现的视图中的"取消"按钮(请参阅TableSearch),则会显示正确的TableView以及搜索结果.我只是希望在搜索操作完成后立即执行此步骤,因此在您进行交互之前.在此阶段,当前显示"无结果"标签.方法"filterContentForSearchText"和"shouldReloadTableForSearchString"与原始TableSearch项目相同.
我已经看了SearchDisplayController及其属性的不同类引用,但我还没有找到任何最终解决方案.
我已经在NSOperation完成后明确迭代的部分中尝试了以下内容,但它似乎没有解决问题.
[self.searchDisplayController.searchResultsTableView removeFromSuperview];Run Code Online (Sandbox Code Playgroud)
和
self.searchDisplayController.searchResultsTableView.hidden = YES;Run Code Online (Sandbox Code Playgroud)
这些操作都具有我想要显示的正确视图但是滚动被禁用,直到您更改状态以便再次隐藏视图.但是,可以选择TableView单元格.我基本上想要只启用滚动功能...
在此先感谢您的努力!
我使用UISearchDisplayController和UITableView实现了一个SearchBar来显示搜索结果.我使用libxml2和xpath来解析HTML网站并搜索源代码中所需的内容.由于我是ObjC的新手,我使用Apple提供的示例项目TableSearch作为搜索和显示部分作为开始.一切正常,我可以解析网站上的特定内容,并将它们正确地组合在网站上,并将它们显示在不同的TableView行视图中.我想使用用户输入来搜索特定的网站.我只有以下问题:
如果您查看项目TableSearch(类MainViewController.m),您会注意到它更新了"filteredListContent"并重新加载TableView,并在用户输入时自动显示它:
[...]
#pragma mark -
#pragma mark Content Filtering
- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
{
/*
Update the filtered array based on the search text and scope.
*/
[self.filteredListContent removeAllObjects]; // First clear the filtered array.
/*
Search the main list for products whose type matches the scope (if selected) and whose name matches searchText; add items that match to the filtered array.
*/
for (Product *product in listContent)
{
if ([scope isEqualToString:@"All"] || [product.type isEqualToString:scope])
{
NSComparisonResult result …Run Code Online (Sandbox Code Playgroud)