Reloading / Displaying searchResultsTableView of UISearchDisplayController after search method iteration is finished

删除回忆录丶 提交于 2019-12-06 05:57:57

问题


I have modified the code of Apple's sample iOS project TableSearch in order to use it for searching a webservice by parsing its contents. Everything I have implemented works fine except for one ugly detail when performing a search using the SearchDisplayController's SearchBar. I have changed the behaviour of the SearchDisplayController to make it call my search function first when the "Search" button was tapped.

The problem is that when the search iteration (which is performed in the background in an NSOperationQueue) is finished the "searchResultsTableView" (of the searchDisplayController) is not automatically displayed or not assigned the resulting content. If you then change the SearchBar's text or tap the "Cancel" button from the view which appears when you touch the search field (see TableSearch) the correct TableView appears with the search results. I simply want to have this step to be executed right after the search operation is finished, so before you interact. At this stage the "No Results" label is currently displayed. The methods "filterContentForSearchText" and "shouldReloadTableForSearchString" are unchanged from the original TableSearch project.

I have taken a look at different class references of the SearchDisplayController and its attributes but I could not find any final solution yet.

I have tried the following in a section which is definitely iterated after the NSOperation is finished but it does not seem to solve the problem.

[self.searchDisplayController.searchResultsTableView removeFromSuperview];

and

self.searchDisplayController.searchResultsTableView.hidden = YES;

These operations both have the correct view I want displayed BUT scrolling is disabled until you change the state so that the view is hidden again. It is possible to select TableView cells, though. I basically want to have this just with scrolling enabled...

Thanks in advance for your effort!


回答1:


I have same problem and I just solved it. I had exactly same problem, I wanted disable instant search and when I hit search button, the table didn't load but when I clicked cancel, it loaded up. And If I scroll on table view that didn't load correct result after search, it crashed due to index out of bound.

The thing you need to do is reload searchResultTableView not current tableview. After you filter out your data by search term, put

[self.searchDisplayController.searchResultsTableView reloadData]

to reload your search result, and it will shows up after you hit search button. Hope this help




回答2:


I found that setting the searchBar.text causes searchDisplayController.searchResultsTableView be added to self.view, I solve it like this:

self.searchBar.text = @"xxxx";
[self.searchDisplayController.searchResultsTableView removeFromSuperview];


来源:https://stackoverflow.com/questions/4702945/reloading-displaying-searchresultstableview-of-uisearchdisplaycontroller-after

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!