Problem opening a new ViewController after UIImagePickerController

I try to open a new view (UnprocessedPhotoViewController) right after the delegate function for my UIImagePickerController returns "didFinishPickingImage".

Unfortunately, it looks like I can either open the modal view of the UIImagePickerController, or switch to UnprocessedPhotoViewController as modal, but not both in series.

In the code below, clicking a button activates pickPhoto IBAction. This code successfully activates the UIImagePickerController. After the user selects the image, the didFinishPickingImage delegation function is called, which saves the image in a variable, tries to close the UIImagePickerController mod and open UnprocessedPhotoViewController in the new modal.

Note. If I comment out on ImagePicker and run showPhoto directly, UnprocessedPhotoViewController will be shown successfully. In addition, if I create a new button for launching or viewing, it works successfully, but I cannot launch the views sequentially. I would expect that after the user selects an image, a new view will be launched that will allow the user to process the image.

What is the correct way to ensure that the ImagePicker mod closes and then opens UnprocessedPhotoViewController?

Thanks!!!

code:

- (IBAction)pickPhoto:(id)sender{ //TODO: To be replaced with the gallery control launching code // Load Image Selection Code self.imgPicker = [[UIImagePickerController alloc] init]; self.imgPicker.delegate = self; self.imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; [self presentModalViewController:self.imgPicker animated:YES]; } // Dummy function assumes you either picked (or took a picture =D) of Angie and moves you right to the unprocessed viewing screen. - (void) showPhoto{ // Start new view controller [self dismissModalViewControllerAnimated:YES]; UnprocessedPhotoViewController *upViewController = [[UnprocessedPhotoViewController alloc] initWithNibName:@"UnprocessedPhotoViewController" bundle:nil]; upViewController.imageView.image = selectedImage; upViewController.delegate = self; upViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; [self presentModalViewController:[upViewController animated:YES]]; [upViewController release]; } - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img { selectedImage = img; [[picker parentViewController] dismissModalViewControllerAnimated:YES]; [self dismissModalViewControllerAnimated:YES]; [self showPhoto]; } - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker { [[picker parentViewController] dismissModalViewControllerAnimated:YES]; } 
+1
source share
2 answers

Implement viewDidAppear in your root view controller and based on member data decide to call showPhoto or not. The following example simply reimages UIImagePicker, but any new modal representation will work. viewDidAppear is called whenever the root view controllers view is displayed, so you need to make sure the context is known when it is called. But this is a deterministic way to find out that the modal view manager is missing.

 - (IBAction) showPicker: (id) sender { UIImagePickerController* picker = [[[UIImagePickerController alloc] init] autorelease]; picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; picker.delegate = self; picker.allowsEditing = YES; [self presentModalViewController:picker animated:YES]; } - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { imageChosen = YES; [self dismissModalViewControllerAnimated:YES]; } - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker { imageChosen = NO; [self dismissModalViewControllerAnimated:YES]; } - (void) viewDidAppear: (BOOL) animated { if ( imageChosen ) { [self showPicker: self]; } } 
+4
source

Another way to do this is to wrap the inline firing animation with your own animation, and then catch the AnimDidStop animation event event. This creates a composite animation, so when the inline animation is complete, your (empty) wrapper animation completes you and warns you that you are finished.

This is a little cleaner than the other answer here, IMO, since you don’t have to save the state variable or override viewDidAppear: (in my application, the view manager representing the collector is quite a few objects removed from which the collector management handles, and that would mean that any view controller using my general utility would have to override viewDidAppear: or not work):

 -(void)dismissalAnimationDone:(NSString*)animationID finished:(BOOL)finished context:(void*)context { UIImage* image = (UIImage*) context; // present controllers as you please } -(void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info { [UIView beginAnimations:@"dismissal wrapper" context:image]; [UIView setAnimationDelegate:self]; [UIView setAnimationDidStopSelector:@selector(dismissalAnimationDone:finished:context:)]; [self.delegate dismissModalViewControllerAnimated:YES]; [UIView commitAnimations]; } 
+3
source

All Articles