Added option to use the cached image instead of the placeholder for UIImageView. Replaces #541. Fixes #599
This commit is contained in:
parent
a6f11b3ad7
commit
30f672661c
|
@ -145,6 +145,23 @@
|
|||
*/
|
||||
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock;
|
||||
|
||||
/**
|
||||
* Set the imageView `image` with an `url` and a optionaly placeholder image.
|
||||
*
|
||||
* The download is asynchronous and cached.
|
||||
*
|
||||
* @param url The url for the image.
|
||||
* @param placeholder The image to be set initially, until the image request finishes.
|
||||
* @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
|
||||
* @param progressBlock A block called while image is downloading
|
||||
* @param completedBlock A block called when operation has been completed. This block has no return value
|
||||
* and takes the requested UIImage as first parameter. In case of error the image parameter
|
||||
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean
|
||||
* indicating if the image was retrived from the local cache of from the network.
|
||||
* The forth parameter is the original image url.
|
||||
*/
|
||||
- (void)sd_setImageWithPreviousCachedImageWithURL:(NSURL *)url andPlaceholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock;
|
||||
|
||||
/**
|
||||
* Download an array of images and starts them in an animation loop
|
||||
*
|
||||
|
|
|
@ -77,6 +77,13 @@ static char imageURLKey;
|
|||
}
|
||||
}
|
||||
|
||||
- (void)sd_setImageWithPreviousCachedImageWithURL:(NSURL *)url andPlaceholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock {
|
||||
NSString *key = [[SDWebImageManager sharedManager] cacheKeyForURL:url];
|
||||
UIImage *lastPreviousCachedImage = [[SDImageCache sharedImageCache] imageFromDiskCacheForKey:key];
|
||||
|
||||
[self sd_setImageWithURL:url placeholderImage:lastPreviousCachedImage ?: placeholder options:options progress:progressBlock completed:completedBlock];
|
||||
}
|
||||
|
||||
- (NSURL *)sd_imageURL {
|
||||
return objc_getAssociatedObject(self, &imageURLKey);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue