我在自定义表格单元格中有一个图像视图,我需要从表格视图委托中为其分配一张图片
cell.imageViewLeft = [[UIImageView alloc] initWithImage:[UIImage imageNamed:fxObject.thumbnailName]];
NSLog(@"%@, %@", [UIImage imageNamed:fxObject.thumbnailName], cell.imageViewLeft.image);
日志给了我:
<UIImage: 0xb485310>, (null)
答案 0 :(得分:1)
确保您的IBOutlets
连接正确。
此外,请确保@ synthesize
imageViewLeft
!
cell.imageViewLeft.image = [UIImage imageNamed:fxObject.thumbnailName];
答案 1 :(得分:0)
我必须初始化属性。
- (UIImageView *)imageViewLeft {
if (!_imageViewLeft) {
_imageViewLeft = [[UIImageView alloc] init];
_imageViewLeft.contentMode = UIViewContentModeScaleAspectFill;
_imageViewLeft.clipsToBounds = YES;
[self.contentView addSubview:_imageViewLeft];
}
return _imageViewLeft;
}
- (UIImageView *)imageViewRight {
if (!_imageViewRight) {
_imageViewRight = [[UIImageView alloc] init];
_imageViewRight.contentMode = UIViewContentModeScaleAspectFill;
_imageViewRight.clipsToBounds = YES;
[self.contentView addSubview:_imageViewRight];
}
return _imageViewRight;
}
其他一切都保持不变。我相信如果我们在没有NIB文件的情况下工作并且我们没有制作IBOutlet属性,那么初始化视图的正确方法。