我将相机中的图像保存在NSMutableArray中。当我添加一张图片时,该图片将添加到数组中。但是,问题是当我拍摄另一张照片时,第一张照片被第二张照片代替。我想保存相机拍摄的所有照片。
- (IBAction)takePhoto {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:NULL];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *cameraImage = info[UIImagePickerControllerEditedImage];
self.tempView.image = cameraImage;
camImages = [NSMutableArray arrayWithCapacity:10];
[camImages addObject:self.tempView.image];
//self.chosenImages=camImages;
NSLog(@"the image is=%@",camImages);
[picker dismissViewControllerAnimated:YES completion:NULL];
}
最佳答案
带走camImages = [NSMutableArray arrayWithCapacity:10];
并将其放在viewDidLoad中。
编辑:使用此代替:
UIImage *cameraImage = info[UIImagePickerControllerEditedImage];
self.tempView.image = cameraImage;
if(!camImages)camImages = [[NSMutableArray alloc]init];
camImages = [NSMutableArray arrayWithCapacity:10];
[camImages addObject:self.tempView.image];
//self.chosenImages=camImages;
NSLog(@"the image is=%@",camImages);
[picker dismissViewControllerAnimated:YES completion:NULL];