Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can not access layer's properties of an UIView in UITableViewCell [duplicate]

I'm having a strange problem. I created a class inheriting from UITableViewCell with a member UIView.

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

In the implementation file, I want to access layer's properties of colorView, but xcode shows "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 says "Property 'cornerRadius' cannot be found in forward class object 'CALayer'". However, I can access cornerRadius in other class.

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

Why does this happen! I totally don't have any ideas where I did wrong in the code!

like image 753
Wayne Huang Avatar asked Jan 03 '12 05:01

Wayne Huang


1 Answers

Have you imported <QuartzCore/QuartzCore.h> in this class?

like image 69
Mark Adams Avatar answered Oct 29 '22 22:10

Mark Adams