简体   繁体   English

如何在iOS中以阵列形式添加相机捕获图像

[英]how to add the camera capture images in array in ios

Want to add the camera capture images added in array and load that array in collection view display the all the images 要添加相机捕获的图像添加到数组中并将该数组加载到集合视图中以显示所有图像

///here i get the capture image in picker

if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
{
      UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
      imagePicker.sourceType =  UIImagePickerControllerSourceTypePhotoLibrary;
       imagePicker.delegate = self;
       imagePicker.allowsEditing = YES;
       [self presentViewController:imagePicker animated:YES completion:nil];
 }


- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{

     // in this part how can add the camera capture image in array  
     // and load that array value in collection view..
}

help me how to achieve this... 帮助我如何实现这一目标...

I have not tested what I am about to write, but you could 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 info
   UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];

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

   //reload collectionView
   [self.collectionView reloadData];
}

and in collectionView cellForItemAtIndexPath 并在collectionView cellForItemAtIndexPath

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
   //this is a custom CollectionViewCell
   CollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];

   cell.imageA.image = [_mutableArray objectAtIndex:indexPath.row];

   return cell;

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM