rai*_*lin 8 objective-c uitableview ios ios-simulator
我开始在模拟器下测试我的应用程序,因为我没有任何iOS 6设备,偶然发现了奇怪的问题.我无法设置UITableViewCell的backgroundColor属性.如果我这样:
cell.contentView.backgroundColor = [UIColor redColor];
Run Code Online (Sandbox Code Playgroud)
它只适用于iOS 6,当我使用它时:
cell.backgroundColor = [UIColor redColor];
Run Code Online (Sandbox Code Playgroud)
或这个
[cell setBackgroundColor:[UIColor redColor]];
Run Code Online (Sandbox Code Playgroud)
它仅适用于iOS7.
当我使用它们cell.contentView并且cell.backgroundColor它适用于iOS时......对于这样一个"简单"的属性,它不应该是一个答案吗?或者也许是一些模拟器错误?
更新:如果它改变了同一个tableview和单元格中的任何内容,我accessoryType既不能通过StoryBoard也不能设置代码......
更新2:由于某种原因设置tableview样式为plain删除了我的所有更改,但分组显示为预期...
小智 19
在iOS6中,您需要在willDisplayCell中更改单元格的backgroundColor.这也适用于iOS7,无需特定于版本的代码.
- (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
[cell setBackgroundColor:[UIColor redColor]];
}
Run Code Online (Sandbox Code Playgroud)
我没有看到将contentView AND的背景设置为单元格的问题.iOS 7已经改变了很多这个类.如果您需要与旧系统兼容,那么您需要执行此类操作.
所以是的,你应该同时使用:
cell.contentView.backgroundColor
cell.backgroundColor
Run Code Online (Sandbox Code Playgroud)
尝试更改单元格的背景视图颜色而不是背景颜色。
UIView *myView = [[UIView alloc] init];
myView.backgroundColor = [UIColor whiteColor];
cell.backgroundView = myView;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7630 次 |
| 最近记录: |