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
.
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;
...
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With