iPeter iPeter - 1 year ago 75
Objective-C Question

Can the selected images from library be stored in an array?

I have built a sample project on camera and library. Now, my question is can I store the images that I am selecting from library into an array? I am using this code.

UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
[self.arrImages addObject:chosenImage];

Now by placing breakpoints, I came to know that, in my array always 1object is storing even after I chosen images for more than one times.

Can anyone give my any idea how can I do it?

Any help is highly appreciated.

Answer Source

Try this.

-(void)viewDidLoad {

//declare before NSMutableArray *_mutableArray;
_mutableArray = [[NSMutableArray alloc] init];


-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
 //dismiss UIImagePickerController
[picker dismissViewControllerAnimated:YES completion:Nil];

//take image from anywhere
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];

//store image into NSMutableArray
[_mutableArray addObject:image];

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download