Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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!

like image 443
John Avatar asked Dec 05 '22 23:12

John


1 Answers

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

like image 57
Ha-eun Chung Avatar answered Jan 22 '23 01:01

Ha-eun Chung