Ios6 uitableview setbackgroundcolor未设置UITableViewStyleGrouped表中的颜色

Ios6 uitableview setbackgroundcolor未设置UITableViewStyleGrouped表中的颜色,ios6,Ios6,在iOS 6中 [uitableview setBackgroundColor:]表格样式为uitableview样式分组时未设置颜色 self.view.backgroundColor = TTSTYLEVAR(mainPageBackground); self.tableView.separatorColor = TTSTYLEVAR(mainPageBackground); self.tableView.backgroundView = nil; 相反,会看到默认的条纹背景 如果样式

在iOS 6中

[uitableview setBackgroundColor:]表格样式为uitableview样式分组时未设置颜色

self.view.backgroundColor = TTSTYLEVAR(mainPageBackground);
self.tableView.separatorColor   = TTSTYLEVAR(mainPageBackground);
self.tableView.backgroundView = nil;
相反,会看到默认的条纹背景

如果样式为UITableViewStyleGroup,我们应该如何设置表的背景

self.view.backgroundColor = TTSTYLEVAR(mainPageBackground);
self.tableView.separatorColor   = TTSTYLEVAR(mainPageBackground);
self.tableView.backgroundView = nil;

帮我修好了。不过,您必须小心这可能会产生的其他影响。

我会提醒您将backgroundView设置为零。根据我的经验,在用户在最新的XCode 4.5下滚动时,这会导致显著的渲染性能下降。以下是我对此问题的解决方案,它不会影响滚动性能:

[tableViewInstance setBackgroundView: nil];
- (void) viewWillLayoutSubviews
{
    CGRect rect = [[UIScreen mainScreen] bounds];
    CGRect frame = CGRectMake(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);

    UIView *backgroundView = [[[UIView alloc] initWithFrame:frame] autorelease];
    backgroundView.backgroundColor = [UIColor clearColor];
    self.tableView.backgroundView = backgroundView;
}

另一个简单的解决方案是在IB中更改UITableView的背景色。例如,我将其更改为“白色”,它再次工作

不知何故,将背景色保留为“默认”会使iOS 6不必为代码中的任何其他颜色设置而烦恼。

设置

[tableView setBackgroundView: nil];
在iOS 5中出现问题,因此我使用的是:

UIView* bview = [[UIView alloc] init];
bview.backgroundColor = [UIColor yellowColor];
[tableView setBackgroundView:bview];

iOS 5和iOS 6兼容

将background设置为nil就可以了,是的,它与以前的版本没有任何问题。

在ios 6中,分组表视图的方法(即backgroundColor)已被弃用,因此请改用

[tableview setBackgroundView : nil];

我知道这已被标记为已回答,但以下工作也已完成:

[[UITableView appearance] setBackgroundColor:[UIColor colorWithRed:233.0/255.0 green:233.0/255.0 blue:233.0/255.0 alpha:1.0]];

[[UITableView appearance] setBackgroundView:nil];

这样,您就不必为应用程序中的每个tableView设置默认值。感谢作者的原始提示

是的,这个给我修好了。我使用的语法是:[self.tableView setBackgroundView:nil];请注意,此解决方案可能会在iOS 5中给您带来问题(如果您删除backgroundColor语句),因为iOS将选择默认的tableView背景。这会对iOS 5和iOS 4产生什么影响?我没有看到任何影响,但如果您不确定,您可以始终使用以下内容来阻止它:if([[[UIDevice currentDevice]systemVersion]floatValue]>=6.0)只要您使用Xcode 4.5构建应用程序,这种情况就会发生。我有一个iOS5项目,这个问题也存在。使用“self.tableView.backgroundView=nil;”解决了这个问题。谢谢,我一直在找这个!如果你需要一个透明的背景,你可以在我用黄色的地方用清晰的颜色。很有魅力。。简单和向后兼容,谢谢塞巴斯蒂安!这对我有用。这似乎是一个避免无背景视图带来任何意外后果的好方法。我不会在viewWillLayoutSubviews中设置backgoundView,而是在ViewDiLoad中只设置一次,并使用自动调整大小的掩码。调整backgroundView大小的方法可能会给您带来性能问题。