enormego / EGOImageLoading

What if images on the iPhone were as easy as HTML?
http://developers.enormego.com
801 stars 220 forks source link

Unable to Cancel Image Loading in UITableViewCell on iOS 6 #27

Closed bluesuedesw closed 11 years ago

bluesuedesw commented 11 years ago

iOS 6 has changed the UITableViewCell subclass's willMoveToSuperview: method so that it is no longer called when the cell get's reused. This breaks the following code:

- (void)willMoveToSuperview:(UIView *)newSuperview {
    [super willMoveToSuperview:newSuperview];

    if(!newSuperview) {
        [imageView cancelImageLoad];
    }
}

Also see:

http://stackoverflow.com/questions/12519156/difference-in-uitableviewcell-willmovetosuperview-behavior-between-ios-5-and-io

As a result using a EGOImageView in a UITableView will not only cause the image loading to not get cancelled when scrolled, but when the cells containing EGOImages are scrolled offscreen, images that load in when the tableview finishes moving will often get drawn in the wrong cells.

Can anyone recommend a workaround? I've tried a few things to cancel (overriding prepareForReuse, canceling in cellForRow...) the image loads that get sent offscreen without success.

bluesuedesw commented 11 years ago

Was able to resolve this and cancel the appropriate image load by moving the cancel call to the UITableView delegate CellForRow method... overlooked this before as I was testing so many other img loading libs...

if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
    } else {
        [cell cancelImageLoadForCell]; // custom method that calls [imageView cancelImageLoad];
    }

Glad I can continue to use EGOImageLoading as it's still the most performant remote image loader out there.