0

Im converting an an iPhone app to universal.

One of my functions requires picking a photo from camera roll from a button in a table view controller. Im getting an error saying I need to use a pop over controller to do this.

On iPad, UIImagePickerController must be presented via UIPopoverController'

As this is built in code (im picking this up from another developer) could I get some advice on on doing this properly in code.

UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.delegate = self;
imagePicker.allowsEditing = YES;

[self presentModalViewController:imagePicker animated:YES];

What ive tried so far:

UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.delegate = self;
imagePicker.allowsEditing = YES;
////////
imagePicker.modalPresentationStyle = UIModalPresentationCurrentContext; 
////////
[self presentModalViewController:imagePicker animated:YES];

and

UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.delegate = self;
imagePicker.allowsEditing = YES;
////////
self.modalPresentationStyle = UIModalPresentationCurrentContext;
////////
[self presentModalViewController:imagePicker animated:YES];
JSA986
  • 5,870
  • 9
  • 45
  • 91

1 Answers1

0

You need to use a UIPopoverController.

UIPopoverController *popoverController = [[UIPopoverController alloc]
initWithContentViewController:imagePicker];

popoverController.delegate = self;

[popoverController 
     presentPopoverFromRect:sender
     permittedArrowDirections:UIPopoverArrowDirectionUp
     animated:YES];

Here's an example: http://www.techotopia.com/index.php/An_Example_iOS_4_iPad_Camera_and_UIImagePickerController_Application_(Xcode_4)

  • Thanks for answer, unfortunately that dosent work for me, and also I need it to work on iPhone as well as iPad. The link seems says "There is no page titled "An_Example_iOS_4_iPad_Camera_and_UIImagePickerController_Application_(Xcode_4"." – JSA986 Oct 01 '12 at 19:40