0

Single View controller with single image view:

- (void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];

if (self.imageView.image == nil) {
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
imagePickerController.delegate = self;
[self presentViewController:imagePickerController animated:YES completion:nil];
}
else {   }
}

- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];

[picker dismissViewControllerAnimated:YES completion:nil];
[self performSelector:@selector(composeEmail:) withObject:image afterDelay:1.0];
}

- (void) imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[picker dismissViewControllerAnimated:YES completion:nil];
}

What follows is an MFMailComposer but the imagePicker does not dismiss after selecting 'use photo.' The imagePicker seems to dismiss and then reappear.
Here is a link to a Gist For the ViewController: https://gist.github.com/FIDELHIMSELF/069609eb5489cf4723a1

I get two error warnings:

"Warning: Attempt to present on whose view is not in the window hierarchy!" and "Snapshotting a view that has not been rendered results in an empty snapshot. Ensure your view has been rendered at least once before snapshotting or snapshot after screen updates."

ketan
  • 19,129
  • 42
  • 60
  • 98
Michael Castro
  • 314
  • 4
  • 14

1 Answers1

0

try dismissing the view controller like;

[picker dismissViewControllerAnimated:YES completion:nil];

So for example imagePickerControllerDidCancel delegate method would look like;

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
    [picker dismissViewControllerAnimated:YES completion:nil];
}
Laky
  • 632
  • 3
  • 10
  • Thanks Laky. That does make more sense to be but the picker is not dismissed after I choose the 'use photo' button. Instead the picker disappears briefly and then reappears. – Michael Castro Aug 13 '15 at 04:37
  • @MichaelCastro that's because you are loading the imagePickerController on - (void)viewDidAppear:(BOOL)animated method, so once you dismiss it that method get called again and load the picker again. Btw are u setting the self.imageView.image a value, i.e the picked image. So to pass the nil check at viewDidAppear ? – Laky Aug 13 '15 at 05:07
  • Good point. I am not setting a value to the imageView and so I think it may be unnecessary as is the entire conditional format is have used. Should I load the imagePickerController in the viewDidLoad method? – Michael Castro Aug 13 '15 at 05:30
  • @MichaelCastro don't directly call to load another view controller at viewDidLoad it will throw an error... if you must call it through a timer like, [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(loadImagePicker) userInfo:nil repeats:NO]; In your case I think the best solution is to call it at viewDidLoad using the timer. – Laky Aug 13 '15 at 05:51