2012-01-03 24 views
9

Tôi gặp sự cố lạ. Tôi đã tạo một lớp kế thừa từ UITableViewCell với thành viên UIView.Không thể truy cập các thuộc tính của lớp của UIView trong UITableViewCell

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

Trong tệp triển khai, tôi muốn truy cập thuộc tính của lớp màuView, nhưng xcode hiển thị "không hoàn thành".

@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 nói "Property 'cornerRadius' không thể tìm thấy trong đối tượng lớp chuyển tiếp 'CALayer'". Tuy nhiên, tôi có thể truy cập cornerRadius ở lớp khác.

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

Tại sao điều này xảy ra! Tôi hoàn toàn không có bất kỳ ý tưởng mà tôi đã làm sai trong mã!

Trả lời

0

Cố gắng nhận được đến lớp xem nội dung:

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

Điều này không hiệu quả. self.contentView không có colorView. –

28

Bạn đã nhập khẩu <QuartzCore/QuartzCore.h> trong lớp này?

+0

Không, nhưng tôi đã nhập , và tôi có thể khai báo một biến với kiểu CALayer *. Trong tập tin mà tôi khai báo MTReportPieChartTableViewCell * cell, tập tin đó chỉ nhập . Tôi đã xem xét trường hợp này. –

+0

Đây là lần nhập chính xác, phù hợp với tôi. – KomodoDave

Các vấn đề liên quan