Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting background of searchResultsTableView

I've a problem. I trying to set the background of an searchResultsTableView. Into my SearchViewController implementation, during the viewDidLoad, I want to set the background either of my self.tableView and of self.searchDisplayController.searchResultsTableView. I do this:

- (void)viewDidLoad {
    [super viewDidLoad];

    self.navigationItem.title = @"Search";

    UIColor *customColor = [UIColor colorWithRed:255.0 green:252.0 blue:227.0 alpha:1.0];
    self.tableView.backgroundColor = customColor;
    self.searchDisplayController.searchResultsTableView.backgroundColor = customColor;
}

After this, I've the tableView with my custom light-yellow color but, when I tap the search bar, and the tableView was replaced by searchDisplayController.searchResultsTableView, this results white.

Thanks for any help.

like image 917
Matteo Cappadonna Avatar asked Feb 28 '11 13:02

Matteo Cappadonna


2 Answers

Use this method .. it will call when you start searching..

- (void)searchDisplayController:(UISearchDisplayController *)controller didLoadSearchResultsTableView:(UITableView *)tableView
{
    tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"default.png"]];
}

Screenshot of search results table view with custom background.

like image 171
k-thorat Avatar answered Nov 09 '22 15:11

k-thorat


That i-Blue's solution with didLoadSearchResultsTableView works just fine. However I define search result background color this way:

- (void)viewWillAppear:(BOOL)animated
{
    self.searchDisplayController.
    searchResultsTableView.backgroundColor =
        [UIColor blueColor];
    [super viewWillAppear:animated];
}

So far no problems.

like image 29
JOM Avatar answered Nov 09 '22 15:11

JOM