0
votes

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.

1
Check the answer here, answered in similar question here, stackoverflow.com/a/3919894/2458651zaheer
@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
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

1 Answers

0
votes

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];
    }
}