Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS - How to check if a modal view is present

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.

like image 980
Evan Johnson Avatar asked Mar 17 '11 10:03

Evan Johnson


People also ask

How do I know if a ViewController is visible?

The view's window property is non-nil if a view is currently visible, so check the main view in the view controller: Invoking the view method causes the view to load (if it is not loaded) which is unnecessary and may be undesirable. It would be better to check first to see if it is already loaded.

What is a UIViewController?

The UIViewController class defines the shared behavior that's common to all view controllers. You rarely create instances of the UIViewController class directly. Instead, you subclass UIViewController and add the methods and properties needed to manage the view controller's view hierarchy.

What is presentedViewController Swift?

In Apple's developer documentation, the property presentedViewController in UIViewController is described as "The view controller that is presented by this view controller, or one of its ancestors in the view controller hierarchy".

What is a view modal?

The Modal View pattern is a small container for displaying information. Dialogs contain a title, content area, and buttons. Modal Views can appear automatically (alerts, banners) or after a user interaction (modal views, popup menus).


1 Answers

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:

BOOL modalPresent = (self.modalViewController); 

If you want to check for a particular modal view controller, you can get the modal view controller's class name like this:

NSString *modalClassName = NSStringFromClass([self.modalViewController class]); 
like image 147
arlomedia Avatar answered Sep 18 '22 15:09

arlomedia