Skip to content

Instantly share code, notes, and snippets.

@YGeorge
Created March 12, 2014 07:33
Show Gist options
  • Save YGeorge/9502431 to your computer and use it in GitHub Desktop.
Save YGeorge/9502431 to your computer and use it in GitHub Desktop.
- (void)setPhotoByURLString:(NSString *)URLString {
if (URLString) {
URLString = [URLString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
SDImageCache *imageCache = [SDImageCache sharedImageCache];
[imageCache queryDiskCacheForKey:URLString done:^(UIImage *image, SDImageCacheType cacheType)
{
if (image) {
NSLog(@"image not null!!");
[self.photoView setImage:image];
}
else {
__weak UIImageView *wphotoView = self.photoView;
[self.photoView setImageWithURL:[NSURL URLWithString:URLString]
placeholderImage:[UIImage imageNamed:@"DefaultPhoto"]
completed:^(UIImage *loadedImage, NSError *error, SDImageCacheType cacheType) {
if (loadedImage) {
wphotoView.image = loadedImage;
[[SDImageCache sharedImageCache] storeImage:loadedImage forKey:URLString];
dispatch_async(dispatch_get_main_queue(), ^{
wphotoView.image = loadedImage;
});
}
}];
}
}];
} else {
self.photoView.image = nil;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment