In my app I can call a UIViewControle in both mode: Push and ModalDialog.
How can I determine, once the UIViewController is active, if has been called as Push or Modal Dialog ?
In my app I can call a UIViewControle in both mode: Push and ModalDialog.
How can I determine, once the UIViewController is active, if has been called as Push or Modal Dialog ?
You can check modalViewController
property of parent view controller like this:
if ([self.parentViewController.modalViewController isEqual:self]) {
NSLog(@"Modal");
} else {
NSLog(@"Push");
}
Just remember to check it after the view has been pushed/presented.
This works for me:
if(self.presentingViewController){
//modal view controller
}else{
}
In case you haven't figured this out yet, I'll share my situation and how I detected whether I'm in a modal view controller.
I have a segue which presents a view controller modally. This view controller is embedded in a navigationController so that I inherit all the good UIBarButtonItem capabilities.
if ([self.parentViewController.presentingViewController.modalViewController isEqual:self.parentViewController]) {
NSLog(@"I'm in a modal view controller!");
}
Hope this helps
The thing is the viewController may not be presented itself, but the collection view controller that contains it is. Maybe more general case will be useful for somebody:
- (BOOL)isModal {
return self.presentingViewController.presentedViewController == self
|| (self.navigationController != nil && self.navigationController.presentingViewController.presentedViewController == self.navigationController)
|| [self.tabBarController.presentingViewController isKindOfClass:[UITabBarController class]];
}