【问题标题】:remove image from tableViewCell created programmatically从以编程方式创建的 tableViewCell 中删除图像
【发布时间】:2011-02-06 17:37:57
【问题描述】:

我想移动一个单元格中包含的 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];以前使用过,将其删除,但不会创建新图像。

【问题讨论】:

    标签: iphone cocoa-touch uitableview uikit cell


    【解决方案1】:

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

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

    【讨论】:

    • 它正在使用第一个建议的选项!太好了,谢谢本!!
    • 非常感谢本。它也对我有用。从现在开始,我一直在寻找解决方案。非常感谢!!!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-07
    • 2017-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多