检查视图控制器是以模态方式呈现还是在推理堆栈上推送 [英] Check if view controller is presented modally, or pushed on a navigation stack

查看:104
本文介绍了检查视图控制器是以模态方式呈现还是在推理堆栈上推送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何在我的视图控制器代码中区分:

How can I, in my view controller code, differentiate between:


  • 以模态方式呈现

  • 推送导航堆栈

两者 presentsViewController isMovingToParentViewController 在这两种情况下都是 YES ,所以不是很有帮助。

Both presentingViewController and isMovingToParentViewController are YES in both cases, so are not very helpful.

什么复杂化事情是我的父视图控制器有时是模态的,在其上推送要检查的视图控制器。

What complicates things is that my parent view controller is sometimes modal, on which the to be checked view controller is pushed.

事实证明我的问题是我嵌入了我的 HtmlViewController UINavigationController 中,然后显示。这就是为什么我自己的尝试和下面的好答案都无效。

It turns out my issue is that I embed my HtmlViewController in a UINavigationController which is then presented. That's why my own attempts and the good answers below were not working.

HtmlViewController*     termsViewController = [[HtmlViewController alloc] initWithDictionary:dictionary];
UINavigationController* modalViewController;

modalViewController = [[UINavigationController alloc] initWithRootViewController:termsViewController];
modalViewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentViewController:modalViewController
                   animated:YES
                 completion:nil];

我想我最好告诉我的视图控制器何时是模态,而不是试图确定。 / p>

I guess I'd better tell my view controller when it's modal, instead of trying to determine.

推荐答案

带上一粒盐,没有测试。

Take with a grain of salt, didn't test.

- (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;
 }

这篇关于检查视图控制器是以模态方式呈现还是在推理堆栈上推送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆