Created
October 11, 2012 21:04
-
-
Save alexito4/3875476 to your computer and use it in GitHub Desktop.
Checking whether ViewController is presented as Modal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// UIViewController+ModalCheck.h | |
// | |
// Created by Felipe Sabino on 06/14/11 | |
#import <UIKit/UIKit.h> | |
@interface UIViewController (ModalCheck) | |
-(BOOL)isPresentedAsModal; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// UIViewController+ModalCheck.m | |
// | |
// Created by Felipe Sabino on 06/14/11 | |
#import "UIViewController+ModalCheck.h" | |
@implementation UIViewController (ModalCheck) | |
-(BOOL)isPresentedAsModal { | |
BOOL isModal = ((self.parentViewController && self.parentViewController.modalViewController == self) || | |
//or if I have a navigation controller, check if its parent modal view controller is self navigation controller | |
( self.navigationController && self.navigationController.parentViewController && self.navigationController.parentViewController.modalViewController == self.navigationController) || | |
//or if the parent of my UITabBarController is also a UITabBarController class, then there is no way to do that, except by using a modal presentation | |
[[[self tabBarController] parentViewController] isKindOfClass:[UITabBarController class]]); | |
//iOS 5+ | |
if (!isModal && [self respondsToSelector:@selector(presentingViewController)]) { | |
isModal = ((self.presentingViewController && self.presentingViewController.modalViewController == self) || | |
//or if I have a navigation controller, check if its parent modal view controller is self navigation controller | |
(self.navigationController && self.navigationController.presentingViewController && self.navigationController.presentingViewController.modalViewController == self.navigationController) || | |
//or if the parent of my UITabBarController is also a UITabBarController class, then there is no way to do that, except by using a modal presentation | |
[[[self tabBarController] presentingViewController] isKindOfClass:[UITabBarController class]]); | |
} | |
return isModal; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment