本文介绍了无法在iOS6中设置UITableViewCell的背景颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始在模拟器下测试我的应用程序,因为我没有任何iOS 6设备,偶然发现了奇怪的问题。我无法设置UITableViewCell的backgroundColor属性。如果我这样:

I started testing my app under simulator, because I don't have any iOS 6 device and stumbled upon weird problem. I cannot set backgroundColor property of UITableViewCell. If I st this:

cell.contentView.backgroundColor = [UIColor redColor];

它仅适用于iOS 6,当我使用它时:

it is working only for iOS 6, when I use this:

cell.backgroundColor = [UIColor redColor];

或者

[cell setBackgroundColor:[UIColor redColor]];

它仅适用于iOS7。

当我同时使用 cell.contentView cell.backgroundColor 时,它适用于iOS ...不应该这样一个简单的财产是一个答案吗?或者它可能是一些模拟器错误?

When I use both cell.contentView and cell.backgroundColor it's working for both iOS... shouldn't it be one answer for such a 'easy' property? Or maybe it's some simulator bug?

更新:
如果它改变同一个tableview和单元格中的任何内容我无法设置 accessoryType 既不是通过StoryBoard也不是代码......

UPDATE:If it changes anything in the same tableview and cells I cannot set accessoryType neither via StoryBoard nor code...

UPDATE2:由于某种原因将tableview样式设置为plain,删除了我的所有更改,但分组显示为预期.. 。

UPDATE2: for some reason setting tableview style to plain deleted all my changes, but grouped showed as expected...

推荐答案

在iOS6中,您需要在willDisplayCell中更改单元格的backgroundColor。
这也适用于iOS7,不需要特定版本的代码。

In iOS6 you need to change the cell's backgroundColor in willDisplayCell.This works in iOS7 as well, precluding the need for version-specific code.

- (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    [cell setBackgroundColor:[UIColor redColor]];
}

这篇关于无法在iOS6中设置UITableViewCell的背景颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 03:31
查看更多