2

I have the following code:

SecondViewController *secondView = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];

[imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
[imagePicker setCameraOverlayView:secondView.view];
[imagePicker setShowsCameraControls:NO];

[self presentModalViewController:imagePicker animated:YES];

My question is: How can I dismiss the ModalViewController from "SecondViewController"?

JOM
  • 8,139
  • 6
  • 78
  • 111
isiaatz
  • 1,125
  • 4
  • 15
  • 22

2 Answers2

10

You must call the following on imagePicker from a UIImagePickerControllerDelegate method in secondView.

For example:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    // process message
    [imagePicker dismissModalViewControllerAnimated:YES];
}
Nick Bedford
  • 4,365
  • 30
  • 36
  • almost; secondView.view is the overlay, not the delegate, You would need to set the image picker's delegate to secondView as well. – Ed Marty Oct 09 '09 at 13:47
  • *sidenote:* `dismissModalViewControllerAnimated:` is now deprecated in iOS6 – Raptor Jul 25 '13 at 09:22
1

The accepted answer no longer works in iOS7. Below is the method which should be used instead.

Again, this method should be called on the UIImagePicker from the UIImagePickerControllerDelegate.

-(void) imagePickerController:(UIImagePickerController *)picker
             didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    [[picker presentingViewController] dismissViewControllerAnimated:YES completion:NULL];

}
Chris
  • 5,882
  • 2
  • 32
  • 57