Is there a way to check if a modal view is present? I'd like to run a method only if a modal view is present. Also, if I have multiple modal views, is there a way to check if a certain modal view is present.
I use the following code to present and dismiss modal views:
[self presentModalViewController:myModalView animated:YES];
[self dismissModalViewControllerAnimated:YES];
Thank you in advance!
Cheers, Evan
PS. My modal view has a view controller, but I'd like to check if the modal view is present from a separate class that is running asynchronously.
Are you checking the presence of a modal view controller from the parent view controller? If so, you can just check that view controller's modalViewController property:
If you want to check for a particular modal view controller, you can get the modal view controller's class name like this:
You can check the presence of a modal
view controller
from the parentview controller
What worked for me is following:
As far as I tested it, this works for iOS7 and iOS8. Didn't try on iOS6 however.
You can check using:
self.presentedViewController
, which returnsThe view controller that is presented by this view controller, or one of its ancestors in the view controller hierarchy.