remove image from ViewCell created programmatically

I would like to move the imageView contained in a cell and it works, but creates a new image at a new position, keeping the old image (then two are displayed). How could I delete the old one ?? used code:

UIImage *cellImage = [UIImage imageNamed:(@"%@", showIconName)];
UIImageView *imageViewToPutInCell = [[UIImageView alloc] initWithImage:cellImage];

imageViewToPutInCell.frame = CGRectMake(iconPos, 7, cellImage.size.width, cellImage.size.height); 
[cell.contentView addSubview:imageViewToPutInCell];

      

every time i reload the tableView it creates a new overlapping image.

[cell.contentView removeFromSuperview]; used previously, deletes it, but then no new image is created.

+2


source to share


1 answer


There are several ways to do this. Without subclassing, you can set the tag to your imageViewToPutInCell and then use - [UIView viewWithTag:] to find and remove the view:



int            imageViewTag = 1234;

[[cell.contentView viewWithTag: imageViewTag] removeFromSuperview];
imageViewToPutInCell.tag = imageViewTag;
...

      

+2


source







All Articles