我有一个奇怪的问题.我创建了一个继承自UITableViewCell的类,其成员为UIView.
@interface MTReportPieChartTableViewCell : UITableViewCell {
UIView *_colorView;
}
@property (nonatomic, retain) IBOutlet UIView *colorView;
@end
Run Code Online (Sandbox Code Playgroud)
在实现文件中,我想访问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
Run Code Online (Sandbox Code Playgroud)
xcode说"在前向类对象'CALayer'中找不到"属性'cornerRadius'.但是,我可以在其他类中访问cornerRadius.
MTReportPieChartTableViewCell *cell = (MTReportPieChartTableViewCell *) [tableView dequeueReusableCellWithIdentifier:[MTReportPieChartTableViewCell identifier]];
cell.colorView.layer.cornerRadius = 3.0f; // This line works fine!
Run Code Online (Sandbox Code Playgroud)
为什么会这样!我完全没有任何想法,我在代码中做错了!
尝试进入内容视图层:
self.contentView.colorView.layer.cornerRadius = 3.0f;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4336 次 |
| 最近记录: |