我该怎么做?
如果我这样设置,它会完美运行:
if(indexPath.row == lastSelectedCell) {
// last cell
TWMainViewExpandedCell *cell = (TWMainViewExpandedCell *)[tableView dequeueReusableCellWithIdentifier:ExpandedCellIdentifier];
if (cell == nil) {
cell = (TWMainViewExpandedCell *)[[[NSBundle mainBundle] loadNibNamed:@"MainViewExpandedCell" owner:self options:nil] objectAtIndex:0];
_circleImage.image = [UIImage imageNamed:@"circle"];
}
return cell;
}
但是,当尝试从此处设置相同的图像属性时(顺便说一句,这是 UITableViewCell 的子类):
@implementation TWMainViewExpandedCell
-(id)initWithCoder:(NSCoder *)aDecoder
{
NSLog(@"initWithCoder");
self = [super initWithCoder: aDecoder];
if (self) {
_circleImage.image = [UIImage imageNamed:@"circle"];
}
return self;
}
最后一个不起作用。为什么?我知道正在调用 initWithCoder。
最佳答案
调用 initWithCoder:
时,您的 circleImage
socket 尚未连接,因此它仍然是 nil
。在 awakeFromNib
中执行此操作。
关于ios - 如何从 initWithCode 为自定义 Cell 设置 UIImageView 的图像属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17690260/