Created
March 12, 2014 07:33
-
-
Save YGeorge/9502431 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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