SDWebImage is very amazing, but DLImageLoader is absolutely incredible, and a key part of many large production applications
stack overflow
It is surprisingly easy to use.
To avoid skimming issues, just enter a delay before starting the image upload. So essentially this ... this is simple
dispatch_after_secs_on_main(0.4, ^ { if ( ! [urlWasThen isEqualToString:self.currentImage] ) { // so in other words, in fact, after a short period of time, // the user has indeed scrolled away from that item. // (ie, the user is skimming) // this item is now some "new" item so of course we don't // bother loading "that old" item // ie, we now know the user was simply skimming over that item. // (just TBC in the preliminary clause above, // since the image is already in cache, // we'd just instantly load the image - even if the user is skimming) // NSLog(@" --- --- --- --- --- --- too quick!"); return; } // a short time has passed, and indeed this cell is still "that" item // the user is NOT skimming, SO we start loading the image. //NSLog(@" --- not too quick "); [DLImageLoader loadImageFromURL:urlWasThen completed:^(NSError *error, NSData *imgData) { if (self == nil) return; // some time has passed while the image was loading from the internet... if ( ! [urlWasThen isEqualToString:self.currentImage] ) { // note that this is the "normal" situation where the user has // moved on from the image, so no need toload. // // in other words: in this case, not due to skimming, // but because SO much time has passed, // the user has moved on to some other part of the table. // we pointlessly loaded the image from the internet! doh! //NSLog(@" === === 'too late!' image load!"); return; } UIImage *image = [UIImage imageWithData:imgData]; self.someImage.image = image; }]; });
This is an “incredibly simple” solution.
IMO, after extensive experimentation, actually works significantly better than a more sophisticated tracking solution when scrolling through scrolling.
once again, DLImageLoader makes all this extremely simple
Note that the section of the above code is just a “normal” way to load an image inside a cell.
Here is a typical code that will do this:
-(void)imageIsNow:(NSString *)imUrl { // call this routine o "set the image" on this cell. // note that "image is now" is a better name than "set the image" // Don't forget that cells very rapidly change contents, due to // the cell reuse paradigm on iOS. // this cell is being told that, the image to be displayed is now this image // being aware of scrolling/skimming issues, cache issues, etc, // utilise this information to apprporiately load/whatever the image. self.someImage.image = nil; // that UIImageView self.currentImage = imUrl; // you need that string property [self loadImageInASecIfItsTheSameAs:imUrl]; } -(void)loadImageInASecIfItsTheSameAs:(NSString *)urlWasThen { // (note - at this point here the image may already be available // in cache. if so, just display it. I have omitted that // code for simplicity here.) // so, right here, "possibly load with delay" the image // exactly as shown in the code above ..... dispatch_after_secs_on_main(0.4, ^ ...etc.... ...etc.... }
Again all this is easily possible thanks to the DLImageLoader, which is awesome. This is a stunningly robust library.