问题
When my iOS app launches for the first time, I automatically open a "welcome" modal like this:
UIViewController *intro = [self.storyboard instantiateViewControllerWithIdentifier:@"intro"];
intro.modalPresentationStyle = UIModalPresentationFullScreen;
//Show the modal
[self presentViewController:intro animated:NO completion:nil];
Inside that modal, the user is instructed to link the app to Dropbox. They tap a button that fires this:
[[DBSession sharedSession] linkFromController:self];
This is a Dropbox SDK method that opens a Dropbox authentication UIWebView in another modal that looks like this: http://d.pr/i/6ZnC
Once they sign in, the modal automatically animates closed.
I then try to close the original intro modal with this:
[self dismissViewControllerAnimated:YES completion:nil];
But I get this warning and the modal does not close:
Warning: Attempt to dismiss from view controller <PPIntroViewController: 0xf296ab0> while a presentation or dismiss is in progress!
Here's what I've tried:
- I put an artificial delay right before
dismissViewControllerAnimated
to let the Dropbox modal close, but it doesn't help:[NSThread sleepForTimeInterval:2.0];
- I've tried turning off the animation:
[self dismissViewControllerAnimated:NO completion:nil];
and that doesn't help either. - I've tried checking for the modal dismissal already in progress:
if(![self isBeingDismissed]){ ... }
and no luck.
Any ideas? How can I determine what exactly is presenting/dismissing and preventing the modal from closing?
iOS 7 + Xcode 5
回答1:
I found that issue. You can see this line in DBSession+ios.m
[rootController presentModalViewController:navController animated:YES];
So, internally they will present their authentication view controller from self
. Already you've present your view controller from self
. So when either they or you try to dismiss view controller from self, give this warning because it had presenting view controller. So instead of pass self to dropBox, pass intro
view controller.
[[DBSession sharedSession] linkFromController:intro];
回答2:
Try calling the
[self dismissViewControllerAnimated:YES completion:nil];
From inside the introViewController rather than from in the root one. This should call on self.presentingViewController if there is no other modal. So I'd nest one in the completion handle block of the first
回答3:
I Found that this issue occurs if you trying to push/dismiss view controller while previous transaction (animation) in progress.
Take NSTimer
and dismissViewController between 0.50 to 1 second. This is helpful trick so your current viewController has done its animation.
Otherwise not sure but try to set NO with dismissViewControllerAnimated
.
[self dismissViewControllerAnimated:NO completion:nil];
来源:https://stackoverflow.com/questions/21898920/warning-when-attempting-to-dismiss-view-controller-modal-within-a-modal