表格样式为UITableViewStyleGrouped时,
[uitableview setBackgroundColor:]未设置颜色
而是可以看到默认的条纹背景。
如果样式是UITableViewStyleGrouped
,我们应该如何设置表格的背景答案 0 :(得分:31)
[tableViewInstance setBackgroundView: nil];
答案 1 :(得分:19)
设置
[tableView setBackgroundView: nil];
在iOS 5中给我带来问题所以我使用的是:
UIView* bview = [[UIView alloc] init];
bview.backgroundColor = [UIColor yellowColor];
[tableView setBackgroundView:bview];
iOS 5和6兼容!
答案 2 :(得分:5)
self.view.backgroundColor = TTSTYLEVAR(mainPageBackground);
self.tableView.separatorColor = TTSTYLEVAR(mainPageBackground);
self.tableView.backgroundView = nil;
为我修好了。你必须要小心这可能带来的其他影响。
答案 3 :(得分:4)
另一个简单的解决方案是在IB中更改UITableView的背景颜色。例如,我改为“白色”,它再次起作用。
不知何故,将背景颜色保留为“默认”会使iOS 6不会对代码中的任何其他颜色设置感到烦恼。
答案 4 :(得分:3)
我会提醒将backgroundView设置为nil。根据我的经验,这会导致在最新的XCode 4.5下用户滚动期间出现明显的渲染性能。以下是我对此问题的解决方案,它不影响滚动性能:
- (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;
}
答案 5 :(得分:1)
[tableview setBackgroundView : nil];
答案 6 :(得分:1)
我知道这已被标记为已回答,但以下情况也有效:
[[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设置。感谢作者的原始提示!
答案 7 :(得分:0)
将背景设置为nil可以完成这项工作,是的,以前的版本不会出现任何问题。