我想移动单元格上包含的 imageView 并且它可以工作,但在新位置创建新图像并保留旧图像(然后显示两个)。我怎样才能删除旧的?使用的代码:
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 时,它都会创建一个新的重叠图像。
[cell.contentView removeFromSuperview];以前使用过,将其删除,但不会创建新图像。
有几种方法可以做到这一点。如果没有子类化,您可以在 imageViewToPutInCell 上设置标签,然后使用 -[UIView viewWithTag:] 查找并删除视图:
int imageViewTag = 1234;
[[cell.contentView viewWithTag: imageViewTag] removeFromSuperview];
imageViewToPutInCell.tag = imageViewTag;
...
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)