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

编程入门 行业动态 更新时间:2024-10-26 18:25:59
无法在iOS 7(iPad)上更改静态表视图单元格的背景颜色(Unable to change background color of static table view cell on iOS 7 (iPad))

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

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

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

在iPhone模拟器上,一切都OK 而在iPad模拟器上,所有单元都是白色的。

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

backgroundColor清除颜色 contentView.backgroundColor来清除颜色 backgroundView为零

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

很奇怪,同一版本的iOS上的两台设备产生不同的结果。 任何人都可以确认这个错误?

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

ps我刚刚意识到,我忘了设置backgroundView.backgroundColor运行时属性来清除颜色,我目前无法访问Mac。 也许这会做的伎俩。

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:

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).

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

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

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

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

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).

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

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. 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上为我工作

Do this:

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

Work for me on IOS7

更多推荐

本文发布于:2023-08-05 00:02:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1423173.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:视图   静态   单元格   颜色   背景

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!