无法更改iOS 7(iPad)上静态表格视图单元格的背景颜色

Kov*_*dra 37 iphone objective-c uitableview ipad ios

在iPad设备上运行时,我无法在iOS 7上更改静态UITableViewCells的背景颜色.您可以使用以下设置轻松检查:

  • 使用两个故事板在Xcode 5中创建一个新的通用项目.
  • 在每个故事板中,只放置一个控制器 - 表视图控制器,并将其设置为初始控制器.
  • 在两个控制器/故事板中的表视图中放置一些(例如3个)静态单元.
  • 在Interface Builder中将每个静态单元格的背景颜色设置为不同的颜色(我使用红色,绿色和清晰的颜色).

现在,在iPhone和iPad模拟器(iOS 7)上运行该应用程序.

在iPhone模拟器上,一切都很好;
在iPad模拟器上,所有细胞都是白色的.

我尝试通过在Interface Builder中为单元格设置运行时属性来强制iPad正常工作:

  • backgroundColor 清除颜色
  • contentView.backgroundColor 清除颜色
  • backgroundView 没有

但没有任何帮助.实际上,设置运行时属性contentView.backgroundColor将改变单元格颜色,但它不能用于清晰的颜色(这意味着在其后面有另一个白色的视图).

相同版本的iOS上的两个设备产生不同的结果是非常奇怪的.其他人可以确认这个bug吗?

有没有人有这个问题的解决方案,或唯一的方法是去动态属性+设置颜色cellForRowAtIndexPath?我想使用静态单元格,因为问题的本质是静态的.

ps我刚刚意识到我忘了尝试将backgroundView.backgroundColor运行时属性设置为清除颜色,而我目前无法访问Mac.也许这会成功.

fab*_*tus 57

做这个:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
     UIImage *pattern = [UIImage imageNamed:@"image.png"];
     [cell setBackgroundColor:[UIColor colorWithPatternImage:pattern]];  
}
Run Code Online (Sandbox Code Playgroud)

在IOS7上为我工作


小智 10

According to Apple's doc:

Whether you use a predefined or custom cell, you can change the cell’s background using the backgroundView property or by changing the inherited backgroundColor property. In iOS 7, cells have a white background by default; in earlier versions of iOS, cells inherit the background color of the enclosing table view. If you want to change the background color of a cell, do so in the tableView:willDisplayCell:forRowAtIndexPath: method of your table view delegate.

So no matter what color you set in tableView:cellForRowAtIndexPath:, iOS 7 changes it to white later. Just set it in tableView:willDisplayCell:forRowAtIndexPath:. Worked for me perfectly.

  • 我认为当发布这个问题时,文档引用文本的最后一行不存在.他们最近可能添加了它.我通过Bug Reporter得知Apple,他们知道这个问题.我不是第一个向他们报告的人(我的问题是另一个仍未解决的问题的副本).我假设他们在文档中添加了上述内容,以便在修复IB问题之前为这个问题提供人们的编程解决方案.在IB中无法覆盖单元格背景颜色是没有意义的.如果您没有设置其他值,则默认颜色应该是默认颜色. (2认同)