Warning when Attempting to Dismiss View Controller (Modal within a Modal)

笑着哭i 提交于 2019-12-24 16:35:22

问题


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:

  1. I put an artificial delay right before dismissViewControllerAnimated to let the Dropbox modal close, but it doesn't help: [NSThread sleepForTimeInterval:2.0];
  2. I've tried turning off the animation: [self dismissViewControllerAnimated:NO completion:nil]; and that doesn't help either.
  3. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!