Barani E
Barani E

Reputation: 49

Warning: Attempt to present <UIImagePickerController: 0x7ca5dc00> on <UIViewController: 0x7b9cac00> which is already presenting (null)

I got this error in using iPad. But iPhone is worked. Please share the solution. My code is given below.

-(void)pickImageFromLibrary
{

    UIImagePickerController *picker10 = [[UIImagePickerController alloc] init];
    picker10.delegate = self;
    picker10.allowsEditing = YES;
    picker10.view.tag=100;


        picker10.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

    [self presentViewController:picker10 animated:YES completion:NULL];


}

Upvotes: 3

Views: 4450

Answers (2)

Rajesh Gupta
Rajesh Gupta

Reputation: 127

you should try this code!

[self.presentedViewController dismissViewControllerAnimated:NO completion:nil];

Upvotes: 2

Adrian P
Adrian P

Reputation: 6529

UIImagePickerCopntroller must be presented in popover in iPad. take a look at the following code for iPad:

    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
    UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:picker];
    [popover presentPopoverFromRect:self.selectedImageView.bounds inView:self.selectedImageView permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
    self.popOver = popover;
} else {
    [self presentModalViewController:picker animated:YES];
}

don't forget to add a strong property for the popover:

@property (nonatomic, strong) UIPopoverController *popOver;

here are the delegate methods for dismissing it:

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

-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker

here is the link to the class reference for more info: Class Refference

Upvotes: 0

Related Questions