2012-01-03 3 views
9

이상한 문제가 있습니다. UIView 멤버를 사용하여 UITableViewCell에서 상속하는 클래스를 만들었습니다.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'는 (는) 정방향 클래스 개체 'CALayer'에서 찾을 수 없다고 말합니다." 그러나 다른 클래스의 cornerRadius에 액세스 할 수 있습니다.

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

왜 이런 일이 발생합니까? 나는 코드에서 잘못한 아이디어가 전혀 없다!

답변

0

봅니다 내용보기 층에 도착 :

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

이것은 작동하지 않습니다. self.contentView에는 colorView가 없습니다. –

28

당신이이 클래스의 <QuartzCore/QuartzCore.h> 수입 적이 있습니까?

+0

아니요,하지만 을 가져 왔고 CALayer * 유형의 변수를 선언 할 수있었습니다. MTReportPieChartTableViewCell * 셀을 선언 한 파일에서 해당 파일은 만 가져옵니다. 나는이 사건을 고려했다. –

+0

이것은 올바른 수입이며, 저에게 효과적입니다. – KomodoDave

관련 문제