在我的自定义单元格子类中,当用户选择一个单元格时,我想更改其上的图像,这是保留的属性。没有笔尖,一切都是代码。
问题:
-首先,即使没有选择任何内容,单元格仍然会显示新图像。
-第二,当我点击单元格没有任何变化;
-(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];
}
在代码示例中,您不需要检查它是否被选中。
-(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
}
}