开发者

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 开发者_如何学JAVApicker, 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'


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??


Try this...

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


You're releasing modal before presenting it. Try this:

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


Ah. It looks like you can't present and dismiss a modal view controller in the same method.

You could use a property (to help with memory management) to store the info dictionary, and an ivar to store something like "didSelectImage". Then in viewDidAppear: of your view controller, if didSelectImage == YES, present your view controller modally using the details in the info dictionary.

Be sure to reset didSelectImage back to NO and set the info dictionary property to nil once they're not needed anymore.


This worked for me:

[myViewControllerA presentModalViewController:myViewControllerB];
//... let myViewControllerB do its job
[myViewControllerB presentModalViewController:myViewControllerC];
//... let myViewControllerC do its job
[myViewControllerA dismissModalViewControllerAnimated:YES];

That is, you present the View Controllers like this A => B(modal) => C(modal), and you then call dismiss from View Controller A in order to miss both B and C at once.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜