Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
464 views
in Technique[技术] by (71.8m points)

iphone - How to pick multiple images from UIImagePickerController in ios

I am trying to simply enable picking multiple images from photolibrary using the UIImagePickerController.I'm relatively new to XCode and I don't understand how to allow the user to pick multiple images from the UIImagePickerControler. This is my current code.Please help any body how to pick multiple images from UIImagePickerController.

 -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex

 {
      switch(buttonIndex)
      {
          case 0:

              [self takeNewPhotoFromCamera];
              break;

              case 1:
              [self choosePhotoFromExistingImages];
              default:

              break;
      }

 }

 - (void)takeNewPhotoFromCamera

 {
      if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera])
      {
          UIImagePickerController *controller = [[UIImagePickerController alloc] init];
          controller.sourceType = UIImagePickerControllerSourceTypeCamera;
          controller.allowsEditing = NO;
          controller.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:
 UIImagePickerControllerSourceTypeCamera];
          controller.delegate = self;
          [self.navigationController presentViewController: controller animated: YES completion: nil];
      }

 }

 -(void)choosePhotoFromExistingImages

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

 }


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

 {
      [self.navigationController dismissViewControllerAnimated: YES completion: nil];
      UIImage *image = [info valueForKey: UIImagePickerControllerOriginalImage];
      NSData *imageData = UIImageJPEGRepresentation(image, 0.1);

 }

 - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker;

 {
      [self.navigationController dismissViewControllerAnimated: YES completion: nil];

 }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

With UIImagePickerController you are able to get only one picture. If you need to pick more you need a custom image picker, such as ELCImagePickerController. It works well! You can download it here.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...