remove image from tableViewCell created programmatically

回眸只為那壹抹淺笑 提交于 2019-12-10 11:09:13

问题


I would like to move an imageView contained on a cell and it works but creating a new image at new position keeping old image (then two are shown). How could I remove 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 that I reload tableView, it creates a new overlapped image.

[cell.contentView removeFromSuperview]; used before, removes it but then new image is not created.


回答1:


There are a couple of ways to do this. Without subclassing, you could set the tag on your imageViewToPutInCell, then later on, use -[UIView viewWithTag:] to find and remove the view:

int            imageViewTag = 1234;

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


来源:https://stackoverflow.com/questions/2617543/remove-image-from-tableviewcell-created-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!