0

There is a lot of code out there and it's really varied. Sometimes the segue controller is :init'd, and sometimes it's used as is. It's obviously set to an object before I :init it, but in some cases the controller does not work as expected. There doesn't seem to be any documentation on prepareForSegue that clears this up.

Also I might add that some developers even use a third option and simply redefine what segue they present.

What am I missing?

Example UIImagePickerController for iPad requires :init (no photos are loaded into the picker), on the iPhone it works as expected.

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // This line is required for iPad functionality.
    // UIImagePickerController *segueController = [((UIImagePickerController*)(segue.destinationViewController)) init];

    // This line is all that is required on iPhone/iPod
    UIImagePickerController *segueController = (UIImagePickerController*)segue.destinationViewController;

    segueController.delegate = self;
    segueController.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
}

Another SO Post: iOS7 Storyboard image picker not working :(

Edit

It appears as though there might be an issue with UIImagePickerController:initWithCoder, but I don't know how to verify that.

Community
  • 1
  • 1
chrisp
  • 2,181
  • 4
  • 27
  • 35
  • You should never init a controller (the destination view controller that is) for a segue. The segue instantiates the controller for you. If you have some specific code snippets you have questions on, you should post them. It's hard to answer a non-specific question like this. – rdelmar Apr 04 '14 at 06:16
  • Well the reason it's posted is because the interwebs is scattered with contradictions. That's the reason there is no "specific" code. I can give you an example that I know of -- will amend. – chrisp Apr 04 '14 at 06:25
  • Your edit is too vague to be useful. Every object needs to be instantiated for you to use it. Some times that is done in code, sometimes it's done for you by a storyboard or xib. If you think you have an actual piece of code that shows the use of an object without it having been instantiated, then post it. I would also recommend that you spend less time on the web, and more time with Apple's documentation -- it's a lot more reliable. – rdelmar Apr 04 '14 at 06:31
  • You're definitely the first person to glorify Apple's documentation that I've heard of. :D I will try to dig through the week's worth of examples I've perused (at Apple) for you. – chrisp Apr 04 '14 at 06:39
  • I'm not sure how you would immediately devolve to patronisation. I've even included links to the relevant Apple documentation that you're so fond of. I'm not even sure how age plays any part in this. For all you know I'm 63. Does that make me better? – chrisp Apr 04 '14 at 06:51

1 Answers1

0
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    UIImagePickerController *destinationController = (UIImagePickerController*)segue.destinationViewController;

    destinationController.delegate = self;
    destinationController.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
}

You don't [ alloc] init] a UIViewController.

Schemetrical
  • 5,506
  • 2
  • 26
  • 43
  • Again, that works perfectly fine for my iPhone -- but fails to display the photo album on my iPad's popover (it's an empty popover). Everything stays the same but if I :init the controller the iPad app displays the gallery. That is the issue and question that was detailed in my question. – chrisp Apr 04 '14 at 06:53
  • @jacobsd If you have a popover in your storyboard, there is no need to alloc init it, but if you do not, then always alloc init. – Schemetrical Apr 04 '14 at 06:58
  • I'm following the documentation and using a popover to display my UIImagePickerController. If I just use the passed controller in :prepareForSegue the popover is empty. If I :init the UIImagePickerController it displays and functions as expected. Again, this is not about me thinking I'm not doing something wrong -- I'm asking "What am I doing wrong?". – chrisp Apr 04 '14 at 07:04