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ã!
Điều này không hiệu quả. self.contentView không có colorView. –