In my application,I am allowing user to select one or multiple images from gallery and as the user is selecting the images,I am storing all the url in an array
- (void)elcImagePickerController:(ELCImagePickerController *)picker didFinishPickingMediaWithInfo:(NSArray *)info
{
[self dismissViewControllerAnimated:YES completion:nil];
for (NSDictionary *dict in info) {
url = dict[@"UIImagePickerControllerReferenceURL"];
[self.images addObject:url];
NSLog(@"array value:%@",self.images);
[self.myPDTable reloadData];
}
}
The output I get is
array value:(
"assets-library://asset/asset.JPG?id=74236046-12DA-4E75-9038-A3092D31005B&ext=JPG",
"assets-library://asset/asset.JPG?id=98FC160A-60E1-4F29-80C8-1AED036F1140&ext=JPG",
"assets-library://asset/asset.JPG?id=4D18448E-9796-47AE-A534-FB3E64518B89&ext=JPG",
"assets-library://asset/asset.JPG?id=38099BA1-4988-46CB-ADE9-E1F3F896147A&ext=JPG",
"assets-library://asset/asset.JPG?id=86556040-16C6-47BB-8CBA-F5164771EC9F&ext=JPG"
)
Now my problem is that I don't know how to use these value and display them in my table view cell.
What you've got in each element of your array is an asset URL. To get from an asset URL to an image, start with the ALAssetsLibrary object, call
assetForURL:resultBlock:failureBlock:
to fetch the corresponding asset (the photo file), and, in theresultBlock
, pull out the thumbnail and use it in your interface.Here's some typical code for getting from an ALAsset to a usable image:
However, you've made a very odd design choice here.
assetForURL:resultBlock:failureBlock:
is time-consuming and operates asynchronously; it is not suitable for calling in a table view data source method (when you configure your cells), which needs to be fast. IndidFinishPickingMediaWithInfo:
, why did you ask theinfo
for itsUIImagePickerControllerReferenceURL
? You don't need an array of URLs; you need an array of images! Theinfo
was offering you the image right then (itsUIImagePickerControllerOriginalImage
); why didn't you take it when it was offered? You could have just grabbed the image, sized it down, and stuck the sized-down image into your table data model, ready for use.(Also, it is silly and wasteful to call
reloadData
every time through thefor
loop. You should call it just once, after you've gathered all the images into your model.)