Last active
August 29, 2015 14:07
-
-
Save sergii-frost/f1206eaa0bf1e740375a to your computer and use it in GitHub Desktop.
Example of using SDWebImage
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
- (UIImage *)userImage | |
{ | |
UIImage *cachedImage = nil; | |
NSString *imagePath = self.imageFilename; | |
if (imagePath) | |
{ | |
SDWebImageManager *manager = [SDWebImageManager sharedManager]; | |
NSURL *imageURL = [NSURL URLWithString:imagePath]; | |
if ([manager diskImageExistsForURL: imageURL]) | |
{ | |
cachedImage = [[manager imageCache] imageFromDiskCacheForKey:imagePath]; | |
} | |
else | |
{ | |
[self cacheUserImageForFilename:imagePath]; | |
} | |
} | |
return cachedImage; | |
} | |
- (void) cacheUserImageForFilename:(NSString *)filePath | |
{ | |
SDWebImageManager *manager = [SDWebImageManager sharedManager]; | |
NSURL *imageURL = [NSURL URLWithString:filePath]; | |
if (![manager diskImageExistsForURL:imageURL]) | |
{ | |
[manager downloadImageWithURL:imageURL | |
options:0 | |
progress:nil | |
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) | |
{ | |
NBULogDebug(@"Image loaded %@", error ? error.debugDescription : @"SUCCESS"); | |
}]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment