views:

619

answers:

2

Hey!

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 table view.

+1  A: 

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;
       ...
Felix
Thank you Felix, I've already tried this successfully, but that's not what I want to do. I'd really like if I can set my own subclass of UITableView. I don't wanna just manipulate the properties of the searchResultsTableView.
burki
+1  A: 

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 table view in the method :

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

yonel