-(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?
Please read the exception messages in the device log:
On iPad, UIImagePickerController must be presented via UIPopoverController
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.
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With