IOS 7 - 在TableView中搜索显示控制器白色Scrollview背景 - 无法更改背景颜色

时间:2014-04-18 23:13:19

标签: ios objective-c

在我的应用程序中,我使用黑暗的桌子和细胞。我在故事板中将所有内容设置为黑色,并且在我添加搜索显示控制器之前一切正常。搜索框本身是所需的颜色,但是当我向下拉时,我看到一个白色的滚动视图。我无法在故事板设置中的任何位置找到更改背景颜色。我已经检查了几个地方,包括深入搜索这个网站。任何帮助将不胜感激。

我已经调用了这个帮助器,我在viewDidLoad的stackoverflow上找到并以编程方式将所有背景设置为黑色。它仍然显示为白色。我已经尝试过self.view self.tableView self.searchDisplayController,但仍然没有骰子。

- (void)listSubviewsOfView:(UIView *)view {

    // Get the subviews of the view
    NSArray *subviews = [view subviews];

    [view setBackgroundColor:[UIColor blackColor]];

    for (UIView *subview in subviews)
    {

        [subview setBackgroundColor:[UIColor blackColor]];

        NSLog(@"%@, %@", [subview class], subview.backgroundColor);

        [self listSubviewsOfView:subview];

    }
}

3 个答案:

答案 0 :(得分:4)

无意中我找到了解决这个问题的方法。如果将表视图的backgroundView属性设置为任何内容,例如:

self.tableView.backgroundView = [[UIView alloc] init];

白色背景消失,backgroundColor按预期显示。

答案 1 :(得分:3)

使用此方法..当您开始搜索时,它会调用..

- (void)searchDisplayController:(UISearchDisplayController *)controller didLoadSearchResultsTableView:(UITableView *)tableView
{
    tableView.backgroundColor = [UIColor anyColor];
}

答案 2 :(得分:0)

您需要记住,在搜索时,searchDisplayController会加载另一个表视图。

所以你可能需要设置searchResultsTableView的backgroundColor,如下所示:

[self.searchDisplayController.searchResultsTableView setBackgroundColor:[UIColor purpleColor]]; //Purple couldn't be a good choice :)