无法在UITableViewCell中访问UIView的图层属性

Way*_*ang 9 objective-c ios

我有一个奇怪的问题.我创建了一个继承自UITableViewCell的类,其成员为UIView.

@interface MTReportPieChartTableViewCell : UITableViewCell {
    UIView *_colorView;
}
@property (nonatomic, retain) IBOutlet UIView *colorView;
@end
Run Code Online (Sandbox Code Playgroud)

在实现文件中,我想访问colorView的图层属性,但xcode显示"没有完成".

@implementation MTReportPieChartTableViewCell
@synthesize colorView = _colorView;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.colorView.layer.cornerRadius = 3.0f;    // Error occurs in this line
    }
    return self;
}
@end
Run Code Online (Sandbox Code Playgroud)

xcode说"在前向类对象'CALayer'中找不到"属性'cornerRadius'.但是,我可以在其他类中访问cornerRadius.

MTReportPieChartTableViewCell *cell = (MTReportPieChartTableViewCell *) [tableView dequeueReusableCellWithIdentifier:[MTReportPieChartTableViewCell identifier]];
cell.colorView.layer.cornerRadius = 3.0f;    // This line works fine!
Run Code Online (Sandbox Code Playgroud)

为什么会这样!我完全没有任何想法,我在代码中做错了!

Mar*_*ams 28

<QuartzCore/QuartzCore.h>在这堂课进口了吗?


sha*_*oga 0

尝试进入内容视图层:

self.contentView.colorView.layer.cornerRadius = 3.0f; 
Run Code Online (Sandbox Code Playgroud)