Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SDWebImage] #541

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions SDWebImage/SDWebImageManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,9 @@ SDWebImageManager *manager = [SDWebImageManager sharedManager];
*/
- (BOOL)diskImageExistsForURL:(NSURL *)url;

/**
* Key for URL
*/
- (NSString *)cacheKeyForURL:(NSURL *)url;

@end
13 changes: 12 additions & 1 deletion SDWebImage/UIImageView+WebCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,21 @@
*/
- (void)setImageWithURL:(NSURL *)url;

/**
* 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.
* @see setImageWithPreviousCachedImageWithURL:andPlaceholderImage:
*/
- (void)setImageWithPreviousCachedImageWithURL:(NSURL *)url andPlaceholderImage:(UIImage *)placeholder;

/**
* Set the imageView `image` with an `url` and a placeholder.
*
* The downloand is asynchronous and cached.
* 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.
Expand Down
13 changes: 13 additions & 0 deletions SDWebImage/UIImageView+WebCache.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,25 @@

#import "UIImageView+WebCache.h"
#import "objc/runtime.h"
#import "SDWebImageManager.h"

static char operationKey;
static char operationArrayKey;

@implementation UIImageView (WebCache)

- (void)setImageWithPreviousCachedImageWithURL:(NSURL *)url andPlaceholderImage:(UIImage *)placeholder
{
NSString *key = [[SDWebImageManager sharedManager] cacheKeyForURL:url];
UIImage *lastPreviousCachedImage = [[SDImageCache sharedImageCache] imageFromDiskCacheForKey:key];
if (nil == lastPreviousCachedImage) {
[self setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:nil];
}
else {
[self setImageWithURL:url placeholderImage:lastPreviousCachedImage options:0 progress:nil completed:nil];
}
}

- (void)setImageWithURL:(NSURL *)url
{
[self setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:nil];
Expand Down