Warning: try to represent <UIImagePickerController: 0x7ca5dc00> in <UIViewController: 0x7b9cac00> which already represents (null)

I got this error while using iPad. But the iPhone works. Please share this solution. My code is 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];


}

      

+3


source to share


2 answers


you should try this code!



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

      

+2


source


UIImagePickerCopntroller must be present in iPad to 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 delegation methods:

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

-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker

      

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

0


source







All Articles