UISearchDisplayController with UITableViewController

I have a UITableViewController in which I added a UISearchBar as a tableHeaderView using Interface Builder. Then I added a UISearchDisplayController to nib and set up all the connections ( delegate , searchResultsDelegate , searchContentsController , searchResultsDataSource , all related to the UITableViewController ). Then I implemented all the delegation and data source methods in my code.

It works like a charm, with the exception of a strange mistake: sometimes the view of the search results table will not scroll, and I can see the flash indicator in the main view of the table behind it. I am NSLog'd searchResultsTableView and apparently this is a submatrix of the main table view, and I assume that the reason for the touch problems that I described earlier.

What is my mistake? Is it possible to use the UITableViewController with the UISearchDisplayController ? If so, how can I configure it so that the result table view is not added as a subheading of my main table view?

Update : I found this example that uses the UISearchDisplayController with the UITableViewController , and apparently the view of the lookup table is added to the main view also there. So now I do not think that my problem.

The fact is that I cannot find a significant difference between what I do and what this sample does. I just add the UISearchBar as the UITableView title to the UITableViewController and add the UISearchDisplayController to it ... It looks like iOS gets confused between the main table and the search table when trying to scroll. Do you have any ideas?

Update : Added 200 repression. Please answer only if you know what you are talking about.

+7
source share
4 answers

This was an additional self.tableView.scrollEnabled = YES , which was called as soon as the search data request was completed. Hope this helps anyone who has the same problem in the future.

+9
source

The search display controller controls the display of the search bar and the table view, which displays the search results of data controlled by another view controller.

Here, the searchDisplaycontroller combines the search string and tabelview, which shows the result data in a table view, so a separate table view is not required.

While you are using a UISerarchBar, then it must have at least one UITableView that can show the results in the view. And here you can see the result without even adding SearchDisplayController to view.

+3
source

I think you can try adding the IBOutlet UISearchDisplayController to your class and connect it to your SearchdDisplayController in the nib file. I'm curious that this search controller in your phone automatically connected it to the standard SERachdisaplaycontreoller output in the inspector.

+1
source

The search bar controller uses its own table view, which is added on top of your own. If you set the delegate and the UISearchDisplayController data source to your UITableViewController, then the table view controller must distinguish between the two table views in its delegate methods. If you do not do it right, it may cause an error.

In other words:

 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if (tableView == self.tableView) { return number of rows in data model; } else { perform the search query; return number of rows in search query; } } 

You do something similar for all delegate and dataSource methods.

I am not 100% sure that this is what causes your problem, but not seeing any more source that is hard to say.

0
source

All Articles