Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Checking whether ViewController is presented as Modal - iOS 5-
// UIViewController+ModalCheck.h
//
// Created by Felipe Sabino on 06/14/11
#import <UIKit/UIKit.h>
@interface UIViewController (ModalCheck)
-(BOOL)isPresentedAsModal;
@end
// 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
@felipesabino

This is deprecated for iOS 6+, please check here if that's your case

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.