How to determine if a UIViewController has been called as a ModalDialog?

In my application, I can call UIViewControle in both modes: Push and ModalDialog.

How can I determine when a UIViewController is active if it was called as a Push or Modal Dialog?

+6
cocoa-touch uiviewcontroller modal-dialog
source share
4 answers

You can check the modalViewController property of the parent view controller as follows:

 if ([self.parentViewController.modalViewController isEqual:self]) { NSLog(@"Modal"); } else { NSLog(@"Push"); } 

Remember to check it after the view has been clicked / presented.

+6
source share

This works for me:

  if(self.presentingViewController){ //modal view controller }else{ } 
+5
source share

If you still do not understand this, I will share my situation and find out if I have a modal controller.

I have a segue that represents a view controller modulo. This view controller is built into the navigationController, so I inherit all the good features of the UIBarButtonItem.

 if ([self.parentViewController.presentingViewController.modalViewController isEqual:self.parentViewController]) { NSLog(@"I'm in a modal view controller!"); } 

Hope this helps

+2
source share

The fact is that the viewController cannot be presented itself, but the collection view controller that contains it. Maybe a more general case would be useful for someone:

 - (BOOL)isModal { return self.presentingViewController.presentedViewController == self || (self.navigationController != nil && self.navigationController.presentingViewController.presentedViewController == self.navigationController) || [self.tabBarController.presentingViewController isKindOfClass:[UITabBarController class]]; } 
0
source share

All Articles