Ben Baron
Ben Baron

Reputation: 14815

How to check if modal view controller failed to display?

I have an app that uses modal view controllers for various purposes. Most importantly for this question, we use a modal controller to display the login screen when a user is logged out.

The issue I ran into is that it appears that presentModalViewController:animated: will fail silently if another modal controller is being animated on or off screen when the call is made. It will print to the debug console with a warning, but the method itself doesn't return a BOOL or throw an exception, so I can't seem to check in code whether it failed so I can retry it in a second.

Is there some way to detect that the controller failed to display immediately after calling this method?

Upvotes: 0

Views: 191

Answers (1)

Ben Baron
Ben Baron

Reputation: 14815

So as I was typing this question, I realized I could check presentingViewController (or parentViewController) to see if it was displayed, and if nil, try again.

Tested and it works. Figured I'd post and answer the question anyway for others to find that may run into a similar issue.


Aa few more things I noticed in testing:

  • It looks like if the modal view is not displayed with an animation, it will be successful even if another modal view is animating when you make the call.

  • Calling dismissModalViewControllerAnimated:NO on the controller you are displaying off of, before presenting the modal controller with animation, will also allow it to complete successfully even if another controller is animating.

Upvotes: 2

Related Questions