当用户选择Cell图像时,如何更改Cell图像?

时间:2011-08-08 14:05:00

标签: iphone ios

在我的自定义单元子类中,当用户选择一个单元格时,我想要更改其上的图像,即保留属性。没有笔尖,一切都是代码。

问题:

- 首先,即使没有选择任何内容,单元格仍会显示新图像。

- 第二,当我点击单元格上没有任何变化时;

-(void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
UIImage *cry = [UIImage APP_CRYSTAL_SELECTED];
self.leftImage = [[[UIImageView alloc] initWithImage:cry] autorelease] ;
[self.contentView addSubview:self.leftImage];
 }

1 个答案:

答案 0 :(得分:2)

您不会检查代码示例中是否选中它。

-(void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    if(selected)
    {
        UIImage *cry = [UIImage APP_CRYSTAL_SELECTED];
        self.leftImage = [[[UIImageView alloc] initWithImage:cry] autorelease] ;
        [self.contentView addSubview:self.leftImage];
    }
    else
    {
        //Remove image here if it exists
    }
}