简体   繁体   中英

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.

I have tried setting the image to nil. (imageV is a subclass of HJManagedImageV, source can be found here: 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.

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? If yes, I would try to implement the method prepareForReuse and see if can solve the problem there.

Hope this helps =)

Don't set it to nil, nor hide it. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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