0

After a user selects a picture from their photo library I want to dismiss the imagePickerVierController and present another, but get the error:

Warning: Attempt to dismiss from view controller while a presentation or dismiss is in progress!

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info

{
if (!self.submitPicturesDetailsViewController)
{
    self.submitPicturesDetailsViewController = [[SubmitPictureDetailsViewController alloc] initWithPicture: lPicture];
}
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
{
    [self.submitPicturesDetailsViewController setModalPresentationStyle:UIModalPresentationFormSheet];
    [self.popOver dismissPopoverAnimated:YES];
    [self presentViewController: self.submitPicturesDetailsViewController animated:YES completion: nil];
}else
{
    //[self performSelector:@selector(present) withObject: nil afterDelay: 5.0];
    [self dismissViewControllerAnimated:NO completion:^{
        [self presentViewController: self.submitPicturesDetailsViewController animated:YES completion: nil];
    }];
}
}

I have tried:

[self performSelector:@selector(present) withObject: nil afterDelay: 5.0];

And it works properly so apparently the completion block is not working properly.

Joe Fratianni
  • 790
  • 8
  • 24
  • Check the answer here, answered in similar question here, http://stackoverflow.com/a/3919894/2458651 – zaheer Feb 22 '14 at 03:59
  • @zaheer That answer is from 2010 and is about a different API. Since iOS5, a completion block is passed to a new API, which allows chaining animations. The above code **should** work but doesn't. – Léo Natan Feb 22 '14 at 04:02
  • I checked it myself by creating a dummy project. it worked. can't find the reason for such issue. I think the only option you are left with is calling a selector with .1 sec delay. – santhu Feb 22 '14 at 05:01

1 Answers1

0

The best fool-proof solution I found was to recursively call my method until the prior view controller is no longer loaded.

- (void) present
{
    if (!self.submitPicturesDetailsViewController.isViewLoaded) {
        [self presentViewController: self.submitPicturesDetailsViewController animated:YES completion: nil];
    }else{
        [self performSelector:@selector(present) withObject: nil afterDelay: 0.1];
    }
}
Joe Fratianni
  • 790
  • 8
  • 24