6

I have a storyboard where I created a UINavigationController instance and set its custom class to UIImagePickerController.

If I set imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera in prepareForSegue, everything works fine.

If I set imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary in prepareForSegue, I get a mostly black screen with an empty gray bar on top that I can't dismiss:

[future location of screenshot - I cannot post images]

I can work around this by not using the storyboard. The question I have-- can this be made to work with the storyboard? If not, why not? Why does it only work for presenting the camera?

EDIT: A colleague comments that this may be a new issue for ios7

The code below doesn't work if the segue is triggered by a storyboard

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    NSAssert([segue.destinationViewController isKindOfClass:[UIImagePickerController class]], @"Destination VC should be UIImagePickerController");

    UIImagePickerController *imagePicker = (UIImagePickerController*) segue.destinationViewController;

    imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    imagePicker.allowsEditing = YES;
    imagePicker.delegate = self;

}
Sufiyan Ghori
  • 18,164
  • 14
  • 82
  • 110
stevesliva
  • 5,351
  • 1
  • 16
  • 39
  • 1
    I made the same observation using iOS 8 – Jakob Jan 14 '15 at 16:42
  • @Jakob -- [try this??](http://stackoverflow.com/questions/21145270/ios7-storyboard-image-picker-not-working) I may close this as a duplicate if it works for you. I haven't gotten around to trying/resolving this for myself in the meantime. – stevesliva Jan 14 '15 at 18:38
  • @Jakob -- I see it worked for you based on a comment there. Please vote to close this as a duplicate. Thanks! – stevesliva Jan 17 '15 at 21:16

2 Answers2

2

This question is a duplicate of iOS7 Storyboard image picker not working :(

The answer there:

Initialize the controller UIImagePickerController *controller = [[segue destinationViewController] init];

...appears to work for most people, so I've recommended this be closed as duplicate of that question which has been answered for awhile.

Community
  • 1
  • 1
stevesliva
  • 5,351
  • 1
  • 16
  • 39
0

Definitely strange. The only solution I have found so far is here: ios7-storyboard-image-picker-not-working

You have to manually init the UIImagePickerControllerInstance for same reason. I'm guessing that there is something funky with the 'initWithCodec' method of the UIImagePicker but it is hard to say without access to the source code (gee thanks Apple...).

P.S. Make sure you are also using the right type of segue. UIImagePickerController is picky about how each mode is displayed. 'Camera' can be modal or popover (modal is reccomended). PhotoLibrary MUST be displayed using a popover.

Community
  • 1
  • 1
pbuchheit
  • 1,371
  • 1
  • 20
  • 47