Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Present another modal view from UIImagePickerController

I want to add a confirmation view after the user takes a photo or selects a saved photo. The confirmation view will just show the selected image, with a cancel and upload button in a toolbar.

My UIImagePickerController is presented modally from one of my view controllers, which is controlled by a navigation controller, which is in turn controlled by a tab bar controller.

How do I present my confirmation view modally so that it takes up the full screen (like the image picker view) when the user selects a photo? Ideally, I want something like this:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    [picker dismissModalViewControllerAnimated:YES];
    UIViewController *modal = [[UIViewController alloc] init];
    modal.view = confirmationView;
    [self presentModalViewController:modal animated:YES];
    [modal release];
}

However, that crashes the app. Should I be presenting the the confirmation view modally from the PICKER? If so, how do I make sure that when the confirmation view is dismissed, the picker will not be displayed either?

EDIT:

Fixed the bug in the code I posted. That's what happens when I try to type from memory instead of copy+paste :( Anyways, the suggestions so far don't help.

If I present the modal controller THEN dismiss the picker, nothing happens, presumably since both controllers are subsequently dismissed.

If I dismiss the picker THEN present the modal controller, I get an exception about modal transitions:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Attempting to begin a modal transition from <UINavigationController: 0x6b33940> to <UIViewController: 0x6b62b00> while a transition is already in progress. Wait for viewDidAppear/viewDidDisappear to know the current transition has completed'
like image 631
pmc255 Avatar asked Sep 26 '10 21:09

pmc255


1 Answers

Found the solution. Indeed, the picker needs to be dismissed, and the trick is to turn animations off for that dismissal so it happens immediately, and then present the second modal view.

EDIT: Actually, it gets me ALMOST to what I want. When you dismiss the picker, the original view gets shown for a split second, and then the modal view gets animated. This looks a little funky.

I also tried to keep the picker around and not dismiss it. Instead, I call [picker presentModalViewController:modal animated:YES]. This lets me smoothly transition from the picker to the confirmation view. However, when I'm done with the confirmation view, I need to call [self dismissModalViewControllerAnimated:YES] from the original controller. This has the effect of showing the image picker first before dismissing everything. Again, not quite what I want.

Ideally, I want the same effect that the Facebook iPhone app uses for upload photos. Once you've selected a photo, it transitions seamlessly to a confirmation view. Canceling or confirming from that view will smoothly transition back to the original, main view. It makes it look like the confirmation view is part of the image picker, when it's probably just another custom view.

How do I do this??

like image 87
pmc255 Avatar answered Sep 17 '22 15:09

pmc255