【问题标题】:How to determine if a UIViewController has been called as ModalDialog?如何确定 UIViewController 是否已被称为 ModalDialog?
【发布时间】:2011-03-09 20:53:00
【问题描述】:
在我的应用中,我可以在两种模式下调用 UIViewControle:Push 和 ModalDialog。
一旦 UIViewController 处于活动状态,我如何确定是被调用为 Push 还是 Modal Dialog ?
【问题讨论】:
标签:
cocoa-touch
uiviewcontroller
modal-dialog
【解决方案1】:
您可以像这样检查父视图控制器的modalViewController 属性:
if ([self.parentViewController.modalViewController isEqual:self]) {
NSLog(@"Modal");
} else {
NSLog(@"Push");
}
只记得在视图被推送/呈现后检查它。
【解决方案2】:
这对我有用:
if(self.presentingViewController){
//modal view controller
}else{
}
【解决方案3】:
如果您还没有弄清楚这一点,我将分享我的情况以及我如何检测我是否在模态视图控制器中。
我有一个以模态方式呈现视图控制器的 segue。这个视图控制器嵌入在一个 navigationController 中,因此我继承了所有好的 UIBarButtonItem 功能。
if ([self.parentViewController.presentingViewController.modalViewController isEqual:self.parentViewController]) {
NSLog(@"I'm in a modal view controller!");
}
希望对你有帮助
【解决方案4】:
问题是 viewController 本身可能不会出现,但包含它的集合视图控制器是。也许更一般的情况对某人有用:
- (BOOL)isModal {
return self.presentingViewController.presentedViewController == self
|| (self.navigationController != nil && self.navigationController.presentingViewController.presentedViewController == self.navigationController)
|| [self.tabBarController.presentingViewController isKindOfClass:[UITabBarController class]];
}