Gre*_*reg 56 cocoa-touch uitableview uikit ios
为什么UITableViewCell背景颜色不起作用(在界面生成器中设置)?
我从一些搜索中注意到,在UITableViewController的自定义子类中设置的以下代码确实有效(见下文):
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
cell.backgroundColor = [UIColor redColor];
}
Run Code Online (Sandbox Code Playgroud)
但我仍然想了解为什么界面构建器具有TableViewCell的背景颜色设置,这实际上似乎不起作用?
chr*_*ris 70
这有点晚了,但我刚遇到这个问题......在contentView工作中设置背景颜色:
cell.contentView.backgroundColor = [UIColor redColor];
Run Code Online (Sandbox Code Playgroud)
Shi*_*ack 16
对我有用的是创建我自己的UIView对象,将其设置为UITableViewCell的背景视图.在cellForRowAtIndexPath中:
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
UIView* bgview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1, 1)];
bgview.opaque = YES;
bgview.backgroundColor = [UIColor orangeColor];
[cell setBackgroundView:bgview];
Run Code Online (Sandbox Code Playgroud)
occ*_*lus 11
尝试设置UITableViewCell本身的背景颜色不是你应该怎么做.表格单元格包含五个可以访问的有用视图的集合,其中一个是backgroundView.
推荐阅读:
http://cocoawithlove.com/2009/04/easy-custom-uitableview-drawing.html
然后:
http://cocoawithlove.com/2010/12/uitableview-construction-drawing-and.html
根据Apple文档,您应始终为单元格tableView:willDisplayCell:forRowAtIndexPath:而不是tableView:cellForRowAtIndexPath:方法提供更改.
这个作品!!
(尝试这个)
Apple的IB的设计是通用的,可以应用于多种组件,并且还针对高技术受众(开发人员)。因此,它(作为应用程序)并未被设计为针对每个组件/情况类型正确地完全自定义界面。因此,在这种情况下,设置背景颜色的能力似乎有些误导。
| 归档时间: |
|
| 查看次数: |
48744 次 |
| 最近记录: |