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

参见英文答案 > Property cannot be found on forward class object?2
我有一个奇怪的问题.
我创建了一个从UITableViewCell继承的类与成员UIView.
@interface MTReportPieChartTableViewCell : UITableViewCell {
    UIView *_colorView;
}
@property (nonatomic,retain) IBOutlet UIView *colorView;
@end

在实现文件中,我想访问layer的colorView属性,但xcode显示“no completion”.

@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说“Property’cornerRadius’无法在前向对象”CALayer“中找到.
但是,我可以在其他类中访问cornerRadius.

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

为什么会发生这种情况?我完全没有任何想法,我在代码中做错了!

解决方法

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

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...