Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to control the searchResultsTableView of a UISearchDisplayController?

I wonder how to take control over the table view that is used by the UISearchDisplayController. You can't overwrite the searchResultsTableView property of the UISearchDisplayController, because it is a read-only property.

I've tried to overlay the searchResultsTableView by a custom UITableView. That works just once, but as soon as you try a second search, the real searchResultsTableView is on top again. (I mean, you type in some text in the searchBar, your custom table view is on top and displays the search results, afterwards you press the cancel button. Now, if you repeat this, your custom table won't be displayed and the searchResultTableView of the UISearchDisplayController wil be on top).

Of course, you can try it without a UISearchDisplayController, but I count on the advantages of this class, I just want to customize the tableView.

like image 991
burki Avatar asked Feb 03 '10 15:02

burki


2 Answers

You cannot set the searchResultsTableView, but you can manipulate it in the appropriate delegate method:

-(void)searchDisplayController:(UISearchDisplayController *)controller didLoadSearchResultsTableView:(UITableView *)tableView {
   tableView.backgroundColor = self.tableView.backgroundColor;
   tableView.separatorColor = self.tableView.separatorColor;
       ...
like image 157
Felix Lamouroux Avatar answered Nov 17 '22 07:11

Felix Lamouroux


You have a TableViewDataSource property on the UISearchDisplayController, this data source produces the UITableViewCell. Implement the UITableViewDataSource protocol and you'll have the control over the customization of the tableView in the method :

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

like image 26
yonel Avatar answered Nov 17 '22 08:11

yonel