简体   繁体   English

无法从ImageVIew中清除TableView中重用单元格中的图像

[英]Image in reused cell in a TableView not being cleared from ImageVIew

I have a Tableview containing cells with images, however the cells that are reused still contain the image from the previous cell that is being reused until the new image is downloaded and set. 我有一个包含带图像的单元格的Tableview,但是被重用的单元格仍然包含来自被重用的前一个单元格的图像,直到下载并设置新图像为止。

I have tried setting the image to nil. 我尝试将图像设置为nil。 (imageV is a subclass of HJManagedImageV, source can be found here: HJManagedImageV (imageV是HJManagedImageV的子类,可在此处找到源: HJManagedImageV

[cell.imageV setImage:nil];

the setter 塞特犬

-(void)setImage:(UIImage *)theImage{
    if (theImage==image) {
        //when the same image is on the screen multiple times, an image that is alredy set might be set again with the same image.
        return; 
    }
    [theImage retain];
    [image release];
    image = theImage;
    [imageView removeFromSuperview];
    self.imageView = [[[UIImageView alloc] initWithImage:theImage] autorelease];
    [self addSubview:imageView];
    [imageView setNeedsLayout];
    [self setNeedsLayout];
    [loadingWheel stopAnimating];
    [loadingWheel removeFromSuperview];
    self.loadingWheel = nil;
    self.hidden=NO;
    if (image!=nil) {
        [callbackOnSetImage managedImageSet:self];
    }
}

I have a workaround for by setting imageV to hidden but then I lose the loading spinner and I'd really like to know why setting it to nil isn't working. 我有一个解决方法,可以将imageV设置为hidden,但是我丢失了加载微调器,我真的很想知道为什么将其设置为nil不能正常工作。

Anyone have any ideas, cause I'm all out of them. 任何人都有任何想法,因为我全神贯注。 Or am I missing a step somewhere. 还是我在某个地方错过了一步。

Are the cells a subclass of UITableViewCell? 单元格是UITableViewCell的子类吗? If yes, I would try to implement the method prepareForReuse and see if can solve the problem there. 如果是,我将尝试实现方法prepareForReuse ,看看是否可以解决那里的问题。

Hope this helps =) 希望这可以帮助=)

Don't set it to nil, nor hide it. 不要将其设置为nil,也不要将其隐藏。 We use a similar class and what we do for such cases is to set a start image to be displayed until the new image loads. 我们使用类似的类,在这种情况下,我们要做的是设置要显示的起始图像,直到加载新图像为止。 So in your case you could simply set the image as a blank jpg/png inside your bundle instead of nil 因此,在您的情况下,您可以将捆绑包内的图片设置为空白jpg / png而不是nil

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM