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



我遇到一个奇怪的问题。我创建了一个类从UITableViewCell继承与成员UIView。

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

在实现文件中,我想访问图层的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

xcode说"属性'cornerRadius'无法在forward类对象'CALayer'中找到"。但是,我可以在其他类中访问cornerRadius。

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

为什么会这样?我完全不知道我在代码中哪里做错了!

您在这个班导入<QuartzCore/QuartzCore.h>了吗?

尝试进入内容视图层:

self.contentView.colorView.layer.cornerRadius = 3.0f; 

最新更新