如何检查视图控制器是否以模态方式呈现或推送到导航堆栈上?

2023-05-16移动开发问题
11

本文介绍了如何检查视图控制器是否以模态方式呈现或推送到导航堆栈上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

限时送ChatGPT账号..

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

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

  • 模态呈现
  • 推送到导航堆栈

presentingViewControllerisMovingToParentViewController 在这两种情况下都是 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];

我想我最好告诉我的视图控制器什么时候是模态的,而不是试图确定.

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

这篇关于如何检查视图控制器是否以模态方式呈现或推送到导航堆栈上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

硬件音量按钮更改应用程序音量
Hardware Volume buttons change in app volume(硬件音量按钮更改应用程序音量)...
2024-08-12 移动开发问题
10

Cocos2d - 如何检查不同层中对象之间的交集
Cocos2d - How to check for Intersection between objects in different layers(Cocos2d - 如何检查不同层中对象之间的交集)...
2024-08-12 移动开发问题
8

恢复游戏 cocos2d
Resume game cocos2d(恢复游戏 cocos2d)...
2024-08-12 移动开发问题
6

Cocos2D + 仅禁用 Retina iPad 图形
Cocos2D + Disabling only Retina iPad Graphics(Cocos2D + 仅禁用 Retina iPad 图形)...
2024-08-12 移动开发问题
10

如何将 32 位 PNG 转换为 RGB565?
How to convert 32 bit PNG to RGB565?(如何将 32 位 PNG 转换为 RGB565?)...
2024-08-12 移动开发问题
21

正确的 cocos2d 场景重启?
Proper cocos2d scene restart?(正确的 cocos2d 场景重启?)...
2024-08-12 移动开发问题
7