Pieter Pieter - 2 months ago 16
iOS Question

How can I check if a modal view is currently over my self.window.rootViewController?

I need to check if there is still a modal view over the root view controller.
The problem I am facing is that I have a second modal view coming from some thread that needs to be displayed. I want to delay the second modal view until the first one is gone.
I cannot just launch it after the first is dismissed because the second modal view is conditional.

[self.window.rootViewController presentModalViewController:vc animated:YES];

What I want to do (feel free to suggest a better alternative way):

  1. Check if
    currently has a modal view displayed on top (or is still animating modal view).

  2. use

  3. Check again, and if needed, delay again


Get rootViewController.presentedViewController (available in iOS 5.0+) or rootViewController.modalViewController (available in iOS 2.0+) and see if it's nil.

Also, you don't want to present the second view controller from the secondary thread, all UI stuff has to be done on the main thread.