简体   繁体   English

在表单元格中将图像分配给uiimageview

[英]assigning image to uiimageview in table cell

I have an image View in custom table cell, and I need to assign it a picture from table view delegate 我在自定义表格单元格中有一个图像视图,我需要从表格视图委托中为其分配图片

  cell.imageViewLeft = [[UIImageView alloc] initWithImage:[UIImage imageNamed:fxObject.thumbnailName]];
    NSLog(@"%@, %@", [UIImage imageNamed:fxObject.thumbnailName],  cell.imageViewLeft.image);

The log is giving me: 日志给了我:

<UIImage: 0xb485310>, (null)

Make sure your IBOutlets are connected correctly. 确保您的IBOutlets连接正确。

Additionally, make sure you @ synthesize your imageViewLeft ! 此外,请确保您@ synthesize imageViewLeft

cell.imageViewLeft.image = [UIImage imageNamed:fxObject.thumbnailName];

I had to initilize the properties. 我必须初始化属性。

- (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;
}

Everything else stays same. 其他一切保持不变。 I believe thats the correct way to initialize views if we are working without NIB files and if we are not making IBOutlet properties. 我认为,如果我们不使用NIB文件并且不提供IBOutlet属性,则这是初始化视图的正确方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM