无法更改iOS 7(iPad)上静态表格视图单元格的背景颜色 [英] Unable to change background color of static table view cell on iOS 7 (iPad)

查看:123
本文介绍了无法更改iOS 7(iPad)上静态表格视图单元格的背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am unable to change the background color of static UITableViewCells on iOS 7, when running on iPad device. You can easily check this with following setup:


  • 使用两个故事板在Xcode 5中创建一个新的通用项目。

  • 在每个故事板中,只放一个控制器 - 表视图控制器,并将其设置为初始控制器。

  • 放几个(例如3个)

  • 在Interface Builder中将每个静态单元格的背景颜色设置为不同的颜色(我使用红色,绿色和清晰的颜色)。

  • Make a new universal project in Xcode 5 with two storyboards.
  • In each storyboard, put only one controller - table view controller, and set it as the initial one.
  • Put a few (e.g. 3) static cells in the table view in both controllers/storyboards.
  • Set the background color of each static cell to different colors in Interface Builder (I use red, green, and clear colors).

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

Now, run the app on iPhone and iPad simulators (iOS 7).

在iPhone模拟器上,一切正常;
在iPad模拟器上的
,所有单元格都是白色的。

On the iPhone simulator, everything is ok;
while on the iPad simulator, all cells are colored white.

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

I tried to force iPad to work correctly by setting runtime properties in Interface Builder for cells:


  • backgroundColor to清晰的颜色

  • contentView.backgroundColor 清除颜色

  • backgroundView 到nil

  • backgroundColor to clear color
  • contentView.backgroundColor to clear color
  • backgroundView to nil

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

but nothing helps. Actually, setting the runtime property of contentView.backgroundColor will change the cell color, but it does not work with clear color (which means there is another view colored in white behind it).

相同版本的iOS上的两个设备产生不同的结果是非常奇怪的。任何人都可以确认这个错误吗?

It is very strange that two devices on same version of iOS produce different results. Can anyone else confirm this bug?

有没有人能解决这个问题,或者唯一的办法是在的cellForRowAtIndexPath ?我想使用静态单元格,因为问题的本质是静态的。

Does anyone have a solution to this problem, or the only way is to go for dynamic properties + setting color in cellForRowAtIndexPath? I would like to use static cells, because the nature of the problem is static.

p.s。我刚刚意识到我忘了尝试设置 backgroundView.backgroundColor 运行时属性来清除颜色,目前我无法访问Mac。也许这样可以解决问题。

p.s. I just realized that I forgot to try to set the backgroundView.backgroundColor runtime property to clear color, and I don't have access to a Mac at the moment. Maybe that would do the trick.

推荐答案

这样做:

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

在IOS7为我工作

这篇关于无法更改iOS 7(iPad)上静态表格视图单元格的背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆