Permalink
Browse files

Added option to use the cached image instead of the placeholder for U…

…IImageView. Replaces #541. Fixes #599
  • Loading branch information...
1 parent a6f11b3 commit 30f672661cdef884b0f2dc5c141b0ba97a9ff0ea @bpoplauschi bpoplauschi committed Jun 25, 2014
Showing with 24 additions and 0 deletions.
  1. +17 −0 SDWebImage/UIImageView+WebCache.h
  2. +7 −0 SDWebImage/UIImageView+WebCache.m
View
17 SDWebImage/UIImageView+WebCache.h
@@ -146,6 +146,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
*
* @param arrayOfURLs An array of NSURL
View
7 SDWebImage/UIImageView+WebCache.m
@@ -77,6 +77,13 @@ - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder
}
}
+- (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);
}

0 comments on commit 30f6726

Please sign in to comment.