1

我怎样才能做到这一点?

如果我这样设置,它可以完美运行:

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 正在被调用。

4

1 回答 1

1

调用时您的circleImage插座尚未连接initWithCoder:,因此它仍然是nil. 在awakeFromNib.

于 2013-07-17T02:54:36.620 回答