Uitableview 表视图在iOS7中的显示方式与在iOS6中的不同

Uitableview 表视图在iOS7中的显示方式与在iOS6中的不同,uitableview,ios7,Uitableview,Ios7,代码的相关部分位于-tableView:cellforrowatinexpath:: cell.textLabel.backgroundColor = [UIColor clearColor]; if (indexPath.row == 0) { cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"%d.jpg",result.le

代码的相关部分位于-
tableView:cellforrowatinexpath:

cell.textLabel.backgroundColor = [UIColor clearColor];
if (indexPath.row == 0) {
   cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"%d.jpg",result.level]]];
} else {
   cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"%d.jpg",indexPath.row+OFFSETTOFIRSTROW]]];
}
cell.backgroundView.alpha = 0.5;
cell.backgroundColor = [UIColor darkGrayColor];
if (totalPieces) {
   cell.textLabel.textColor = [UIColor colorWithRed:0.1 green:0.5 blue:0.1 alpha:1.0];
   cell.textLabel.shadowColor = [UIColor blackColor];
   if (indexPath.row == 0) {
      cell.textLabel.shadowColor = [UIColor colorWithRed:0.0 green:0.5 blue:0.0 alpha:1.0];
      cell.textLabel.textColor = [UIColor yellowColor];
      cell.backgroundView.alpha = 1.0;
   }
   cell.textLabel.shadowOffset = CGSizeMake(1.0, 1.0);
} else {
   cell.textLabel.textColor = [UIColor blackColor];
   cell.textLabel.shadowColor = nil;
}
实际上,表的每一行都有自己的背景图像。这在iOS6中正确显示。但在iOS7中,发生的情况是图像被看起来像是背景色的颜色覆盖。也就是说,直到用户滚动表格。当用户滚动表格时,它会正确显示。是什么让它在第一次演示时表现不同?我该怎么做才能修好它

预期结果是覆盖整个单元格的深灰色背景色。在这上面是背景图像,它有一些透明度,背景颜色应该通过它来显示。上面是文本,它有一个透明的背景,因此图像/单元格背景可以显示出来


除非我听到其他消息,否则我想我会做的是堆叠两张图像,而不是使用单元格背景。

这是苹果有意做出的改变。要修复它,请将cell.backgroundColor更改为
[UIColor clearColor]
确定。这个解决方案是有效的,尽管可能有一个更有效的解决方案

cell.textLabel.backgroundColor = [UIColor clearColor];
UIView *backgroundView = [[UIView alloc] initWithFrame:cell.bounds];
backgroundView.backgroundColor = [UIColor darkGrayColor];
if (indexPath.row == 0) {
   [backgroundView addSubview:[[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"%d.jpg",result.level]]]];
   cell.backgroundView = backgroundView;
} else {
   [backgroundView addSubview:[[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"%d.jpg",indexPath.row+OFFSETTOFIRSTROW]]]];
   cell.backgroundView = backgroundView;
}

首先通过将单元格的背景视图设置为nil来清除它。然后设置一个自定义视图

[cell setBackgroundView: nil];
UIView* bview = [[UIView alloc] init];
bview.backgroundColor = [UIColor colorWithPatternImage:@"your image"];
[cell setBackgroundView:bview];

这对我很有用。。希望它也能对你有用…-)祝你好运。

不。那不行。我刚刚编辑了我的帖子。背景不应该很清楚。它应该通过背景图像的透明部分显示。请注意,我的图像是透明的。透明部分需要显示我所说的背景色。我不是简单地用图像替换背景色,这是你的代码所做的。你想同时设置背景色和背景图像吗???然后去定制手机那是另一个选择,当然。但在iOS6中,只需设置背景颜色和背景图像就可以了。我想了解的一部分是潜在的差异是什么。我想这只是一个意外,它在iOS6中工作,因为对文档的简单阅读看起来像是图像和背景色不应该同时出现。据我所知,在tableview单元格视图中,除非创建自定义单元格,否则不能同时设置背景色和图像。而且单元格的图像视图大小也是预定义的。这在文档中并不清楚。事实上,我的建议正好相反。使用超类UIView的属性设置背景色。背景视图是表视图单元格类的属性。我看不到任何迹象表明它们是相互排斥的。它们可以同时使用。唯一的问题是哪个在上面。文档确实说背景视图放在所有其他视图之后。在我看来,这不包括背景色,背景色不是视图(除非在原始答案中指定)。