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

半世苍凉 提交于 2019-12-12 04:56:23

问题


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.


回答1:


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];


}


来源:https://stackoverflow.com/questions/29558314/can-the-selected-images-from-library-be-stored-in-an-array

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!