从tableViewCell中删除图像编程创建 [英] remove image from tableViewCell created programatically

查看:116
本文介绍了从tableViewCell中删除图像编程创建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想移动一个单元格中包含的imageView,它工作,但创建一个新的图像在新的位置保持旧的图像(然后两个显示)。如何删除旧的?使用的代码:

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];

每次重新加载tableView时,都会创建一个新的重叠图像。

every time that I reload tableView, it creates a new overlapped image.

[cell.contentView removeFromSuperview];使用以前,删除它,但然后新的图像不创建。请帮忙!! Thanx

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

推荐答案

有几种方法可以做到这一点。没有子类化,你可以在你的imageViewToPutInCell设置标签,然后使用 - [UIView viewWithTag:]来查找和删除视图:

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;
...

这篇关于从tableViewCell中删除图像编程创建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆