似乎无法一个子层添加到我的UITableViewCell子类

问题描述:

此代码是从的UITableViewCell似乎无法一个子层添加到我的UITableViewCell子类

CALayer* greenLayer = [CALayer layer]; 
greenLayer.backgroundColor = [UIColor greenColor].CGColor; 
CGRect frame = CGRectMake(0, 0, 320, self.bounds.size.height); 
greenLayer.frame = frame; 
[self.backgroundView.layer addSublayer:greenLayer]; 

的一个子类中运行,但没有任何反应

这是导致问题的另一段代码。我错误地检索了单元格。

而不是将你的子层的backgroundView,添加它到小区的contentView

[self.contentView.layer addSublayer:greenLayer]; 

或者,你可以只直接设置内容查看的backgroundColor属性:

self.contentView.backgroundColor = [UIColor greenColor]; 
+0

试过,也不管用。我没有试图做一个绿色的背景btw,只是让我可以看到图层。 – willcodejavaforfood 2012-04-01 21:24:48