Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I know if a ModalViewController is being shown?

I override -orientationChanged in my main ViewController to push ModalViewController A when the device is in landscape mode. When placed back in portrait mode, ModalViewController A is dismissed. However, there are other cases (after button touches) where ModalViewControllers B, C, or D are shown. When those are showing, if the device is turned landscape and turned back, ModalViewController B C or D is dismissed, inappropriately.

I can verify that -orientationChanged on my main ViewController is being messaged even when a ModalViewController is shown. Is there a condition I can add to my -orientationChanged method to bypass that code when ModalViewController B C or D is being shown?

Thank you!

like image 312
ed94133 Avatar asked Aug 21 '10 22:08

ed94133


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.

How check ViewController is presented or pushed in Swift?

modalTransitionStyle = UIModalTransitionStyleCoverVertical; [self presentViewController:modalViewController animated:YES completion:nil];

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.


1 Answers

You can check if the modalViewController property in your main viewcontroller is one of your view controllers.

like image 105
Elfred Avatar answered Sep 22 '22 18:09

Elfred