1

I work on iPad simulator and I want to view image in iPad photo gallery, but it's have problem:

'NSInvalidArgumentException', reason: 'On iPad, UIImagePickerController must be presented via UIPopoverController'

Here is my code. Help me!

- (IBAction)ShowGallery:(id)sender {
        if([UIImagePickerController isSourceTypeAvailable:
            UIImagePickerControllerSourceTypePhotoLibrary]) {
            picker = [[UIImagePickerController alloc]init];
            picker.delegate = self;
            picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
            [self presentModalViewController:picker animated:YES];
        }
binhnt
  • 97
  • 3
  • 11

1 Answers1

0

Instead of PresentModalViewController you have to use a PopoverController in iPad.You can use the following code for that

 UIPopoverController *popOver =[[UIPopoverController alloc] initWithContentViewController:picker];
    [popOver setPopoverContentSize:CGSizeMake(315.0 , 245.0) animated:YES];

    [popOver presentPopoverFromRect:takePictureButton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];    
[picker release];
iOSiOS
  • 214
  • 2
  • 5
  • 10