Reload / Display searchResultsTableView UISearchDisplayController after iteration of the search method is completed

I changed the code of the Apple iOS TableSearch project to use it to search for a web service by analyzing its contents. Everything I implemented works fine except for one ugly detail when doing a search using the SearchDisplayController SearchBar. I changed the behavior of the SearchDisplayController to first call my search function when the Search button was clicked.

The problem is that when the search iteration (running in the background in NSOperationQueue) is completed, the "searchResultsTableView" (of searchDisplayController) is not automatically displayed or assigned to the received content. If you then change the text of the SearchBar or tap the "Cancel" button in the view that appears when you touch the search field (see TableSearch), the correct TableView appears with the search results. I just want this step to be executed immediately after the search operation is completed, so before you start interacting. At this point, the label โ€œNo Resultsโ€ is currently displayed. The methods "filterContentForSearchText" and "shouldReloadTableForSearchString" do not change from the original TableSearch project.

I looked at various references to SearchDisplayController classes and its attributes, but have not yet found a final solution.

I tried the following in a section that definitely repeats after completing NSOperation, but it does not seem to solve the problem.

[self.searchDisplayController.searchResultsTableView removeFromSuperview]; 

and

 self.searchDisplayController.searchResultsTableView.hidden = YES; 

These operations have the correct form that I want to display. BUT scrolling is disabled until you change the state to hide the view again. However, you can select TableView items. I basically want it to be just scroll-enabled ...

Thanks in advance for your efforts!

+4
source share
2 answers

I have the same problem and I just solved it. I had the same problem, I wanted to turn off instant search, and when I clicked the search button, the table did not load, but when I clicked the โ€œCancelโ€ button, it loaded. And if I look at a table view that did not load the correct result after the search, it crashed due to the index from abroad.

What you need to do is reload the searchResultTableView, not the current table. After you filter your search results, put

 [self.searchDisplayController.searchResultsTableView reloadData] 

to reload the search result, and it will appear after clicking the search button. We hope for this help.

+16
source

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

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

Source: https://habr.com/ru/post/1335697/


All Articles