如何在我的 View Controller 代码中区分:
presentingViewController
和 isMovingToParentViewController
在这两种情况下都是 YES
,所以不是很有帮助。
让事情变得复杂的是,我的父 View Controller 有时是模态的,要检查的 View Controller 被推送到它上面。
原来我的问题是我将我的 HtmlViewController
嵌入到 UINavigationController
中,然后显示。这就是为什么我自己的尝试和下面的好答案都不起作用的原因。
HtmlViewController* termsViewController = [[HtmlViewController alloc] initWithDictionary:dictionary];
UINavigationController* modalViewController;
modalViewController = [[UINavigationController alloc] initWithRootViewController:termsViewController];
modalViewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentViewController:modalViewController
animated:YES
completion:nil];
我想我最好告诉我的 View Controller 什么时候是模态的,而不是试图确定。
最佳答案
持保留态度,未测试。
- (BOOL)isModal {
if([self presentingViewController])
return YES;
if([[[self navigationController] presentingViewController] presentedViewController] == [self navigationController])
return YES;
if([[[self tabBarController] presentingViewController] isKindOfClass:[UITabBarController class]])
return YES;
return NO;
}
关于ios - 如何检查 View Controller 是否以模态方式呈现或推送到导航堆栈上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23620276/
相关文章:
objective-c - iOS 6 中用于完成 block 的 dispatch_get_cur
ios - 如何防止 UINavigationBar 在 iOS 7 中覆盖 View 顶部?
iphone - 为 UIView 子类加载 Nib 的正确方法
objective-c - 如何在 Objective-C 中检测未使用的方法和#import
objective-c - IOS:创建带有圆角的 UIImage 或 UIImageView
iphone - 我在 iPhone 上的日期字符串中使用什么格式的字符串来表示毫秒?
objective-c - 如何删除 MKMapView 上的所有注释
objective-c - Swift native 基类或 NSObject