I need to read images from NSDocumentDirectory to multiple uiimageview async so it won’t block the UI.
I know i can use perform selector in background to load a uiimage, but then how can i associate it with the dynamic uiimageview ?
I need to read images from NSDocumentDirectory to multiple uiimageview async so it won’t
Share
One convenient way is to use blocks, something like:
Where you would load the image as data (since
UIImageotherwise loads the image data deferred – when you first access it). It’s also a good idea to decompress the image while still in the background thread, so the main thread doesn’t have to do it when we first use the image.The callback is defined as:
Here’s an
UIImagecategory that implements the decompression code:UIIMage+Decode.h
UIIMage+Decode.m
The sample code provided here assumes that we’re using ARC.