2

I am making an app for iPhone and want to give users the ability to multi-select images from their photo-library. I already have a working code for user to select four images at a time.But i cant select 2 or 3 images at a time.I want to select the 2 or 3 images at a time.I am trying to the following code.please help me anybody.

- (id)initImagePicker
{    
    ELCAlbumPickerController *albumPicker = [[ELCAlbumPickerController alloc] initWithStyle:UITableViewStylePlain];    
    self = [super initWithRootViewController:albumPicker]; 
    if (self) 
    {          
        self.maximumImagesCount = 4; 
        [albumPicker setParent:self];
    }     
    else if (self)   
    {          
        self.minimumImageCount=1;        
        [albumPicker setParent:self];  
    }      
    return self;
}

- (id)initWithRootViewController:(UIViewController *)rootViewController
{  
    self = [super initWithRootViewController:rootViewController]; 
    if (self) 
        self.maximumImagesCount = 4;        
    else if (self)
        self.minimumImageCount=1;   
    return self;
}

-(void)choosePhotoFromExistingImages
{
    ELCImagePickerController *elcPicker = [[ELCImagePickerController alloc] initImagePicker];  
    elcPicker.maximumImagesCount = 4;
    elcPicker.returnsOriginalImage = NO; //Only return the fullScreenImage, not the fullResolutionImage
    elcPicker.imagePickerDelegate = self;
    [self presentViewController:elcPicker animated:YES completion:nil];
}
Anil
  • 2,430
  • 3
  • 37
  • 55
user3222991
  • 341
  • 3
  • 8
  • 16

5 Answers5

2

You should try MWPhotoBrowser Control by Michael Waterfall
He has provided single as well as multiple photo selection


Works on iOS 5.1.1+.
All strings are localisable so they can be used in apps that support multiple languages.

bhavya kothari
  • 7,484
  • 4
  • 27
  • 53
1

In one of my project i've done this thing without ELCImagePickerController. And successfully working that code too. In that project I've added a done button on the navigation bar of image picker controller. Whenever you select a image that image you can grab with in the method called

-(void)imagePickerController:(UIImagePickerController *)pickerdidFinishPickingMediaWithInfo:(NSDictionary *)info

Whenever you are finished with picking you images then you press that done button.with in that method dismiss the view controller.

Using this process you can select and fetch as much as image you want to have.

And my app is working successfully.

Cheers....!!!!!!!

Amitabha
  • 1,664
  • 1
  • 12
  • 30
  • thanks for your response.Please give me any idea or sample code.i have no idea how to select multiple images using UIImagePickercontroller – user3222991 Feb 10 '14 at 07:25
1

Add done button on the navigation bar of uiimagepickercontroller

- (void)navigationController:(UINavigationController *)navigationController
  willShowViewController:(UIViewController *)viewController
                animated:(BOOL)animated
{    
     if (!doneButton) 
    {
        doneButton = [[UIBarButtonItem alloc] initWithTitle:@"Done"
                                                  style:UIBarButtonItemStyleDone
                                                 target:self   action:@selector(saveImagesDone:)];
    }

viewController.navigationItem.rightBarButtonItem = doneButton;
}

First display the image picker using UIImagePickerController

Grab your images

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

    NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
    if ([mediaType isEqualToString:@"public.image"] 
    {
        UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];


        // Get the data for the image
        NSData* imageData = UIImageJPEGRepresentation(image, 1.0);

        NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString* documentsDirectory = [paths objectAtIndex:0];

        // Now we get the full path to the file
        NSString* fullPathToFile2 = [self createName:documentsDirectory]; 
        // and then we write it out
        [imageData writeToFile:fullPathToFile2 atomically:NO];
}
else
{
    // Show Alert
}

}

Close The image picker view controller

-(IBAction)saveImagesDone:(id)sender
{
    [self dismissViewControllerAnimated:YES completion:nil];
    [self loadimages]; // Load your Images
} 

every time you click over an image ,

 -(void)imagePickerController:(UIImagePickerController *)pickerdidFinishPickingMediaWithInfo:(NSDictionary *)

info this method will grab the image for you.

Don't forgot to upvote... Cheers....!!!!!

Amitabha
  • 1,664
  • 1
  • 12
  • 30
0

you need to implement these methods

- (void)elcImagePickerController:(ELCImagePickerController *)picker didFinishPickingMediaWithInfo:(NSArray *)info;

it will return you array of your image selected.(the controller sends back an array of similarly structured dictionaries)

- (void)elcImagePickerControllerDidCancel:(ELCImagePickerController *)picker;
Pawan Rai
  • 3,434
  • 4
  • 32
  • 42
0

Try this:

-(id)initImagePicker{

ELCAlbumPickerController *albumPicker = [[ELCAlbumPickerController alloc] initWithStyle:UITableViewStylePlain];

self = [super initWithRootViewController:albumPicker];
if (self) {
    self.maximumImagesCount = 4;
    self.returnsImage = YES;
    self.returnsOriginalImage = YES;
    [albumPicker setParent:self];
    self.mediaTypes = @[(NSString *)kUTTypeImage, (NSString *)kUTTypeMovie];
}
return self;

}

-(id)initWithRootViewController:(UIViewController *)rootViewController {

self = [super initWithRootViewController:rootViewController];
if (self) {
    self.maximumImagesCount = 4;
    self.returnsImage = YES;
}
return self;

}

-(void)choosePhotoFromExistingImages {

ELCImagePickerController *elcPicker = [[ELCImagePickerController alloc] initImagePicker];  
elcPicker.maximumImagesCount = 4;
elcPicker.returnsOriginalImage = NO; //Only return the fullScreenImage, not the fullResolutionImage
elcPicker.imagePickerDelegate = self;
[self presentViewController:elcPicker animated:YES completion:nil];

}