简体   繁体   中英

Setting UIImageView with image from cache

I cache an image when the user logs in like this:
This is in a Utility.m

UIImage *image = [UIImage imageWithData:newProfilePictureData];

UIImage *mediumImage = [image thumbnailImage:280 transparentBorder:0 cornerRadius:0 interpolationQuality:kCGInterpolationHigh];
UIImage *smallRoundedImage = [image thumbnailImage:64 transparentBorder:0 cornerRadius:9 interpolationQuality:kCGInterpolationLow];

NSData *mediumImageData = UIImageJPEGRepresentation(mediumImage, 0.5); // using JPEG for larger pictures
NSData *smallRoundedImageData = UIImagePNGRepresentation(smallRoundedImage);

Later on I would like to load the small image into an UIImageView :
This is in a UITableView - cellForRowAtIndexPath

[cell.leftIcon setImage:

Does anyone know how I can reference the cached image?

You need something like below method in Utility.m,

+(NSString*)getImage {
    return smallRoundedImage;
}

Then use it like below,

[cell.leftIcon setImage:[Utility getImage]];

PS: This is just an example, you can make this much better based on what's your requirements!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM