Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIImagePickerController crashes in iPad

-(IBAction)selectPressed:(id)sender
{
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    [self presentModalViewController:picker animated:YES];
    [picker release];
}

I am testing this code on iPad and iPhone simulators. In the iPhone simulator (and on real iPhones too) it's ok - gallery appears. But on the iPad simulator (I don't have a device), it crashes. Any ideas why?

like image 863
spe Avatar asked Feb 18 '11 21:02

spe


3 Answers

Please read the exception messages in the device log:

On iPad, UIImagePickerController must be presented via UIPopoverController

like image 70
Max Avatar answered Oct 29 '22 15:10

Max


Max said:

On iPad, UIImagePickerController must be presented via UIPopoverController

It now appears that we can presentModalViewController the UIImagePickerController when its sourceType is set to UIImagePickerControllerSourceTypeCamera. This must be to support the iPad 2's cameras in a full screen view. Max is correct that presentModalViewController crashes on iPads when sourceType is set to anything else.

like image 37
lifjoy Avatar answered Oct 29 '22 15:10

lifjoy


When displaying a modal view controller on the iPad, that view controller also needs it's modalPresentationStyle property to be set in order to display the incoming view.

Here are the options available to you from the documentation:

typedef enum {
   UIModalPresentationFullScreen = 0,
   UIModalPresentationPageSheet,
   UIModalPresentationFormSheet,
   UIModalPresentationCurrentContext,
} UIModalPresentationStyle;
like image 35
Mark Adams Avatar answered Oct 29 '22 16:10

Mark Adams