【问题标题】:Is there a way to detect how many modal view controllers are being presented?有没有办法检测正在呈现多少个模态视图控制器?
【发布时间】:2012-12-19 08:03:10
【问题描述】:

在 iOS 中,提交 modalViewController 非常简单:

[self presentModalViewController:controller animated:YES];

或者:

[[[[[UIApplication sharedApplication] delegate] window] rootViewController] presentModalViewController:controller animated:YES];

modalViewController(如navigationController)内,您可以再次呈现modalViewController。有没有办法检测正在呈现多少个模态视图控制器?否则也许挂钩presentModalViewController:animated:dismissModalViewControllerAnimated: 是个好主意?谢谢!

【问题讨论】:

  • 目标是什么?也许如果您告诉我们知道这一点的意义,我们可以为您提供帮助。

标签: ios cocoa presentmodalviewcontroller


【解决方案1】:

检查这个问题:

Is it possible to determine whether ViewController is presented as Modal?

您可以使用该代码“爬升”您的视图,直到找到不是模态视图控制器的视图。喜欢:

while (isModal)
{
    currentViewController = currentViewController.presentingViewController;

    ...
}

【讨论】:

    【解决方案2】:

    我想我找到了找到最顶层 viewController 的方法,这应该有助于解决这个问题:

    + (UIViewController*)getTopMostViewController {
        UIWindow * window = [UIApplication sharedApplication].keyWindow;
        UIViewController *appRootViewController = window.rootViewController;
        UIViewController *topViewController = appRootViewController;
        while (topViewController.modalViewController != nil) {
            topViewController = topViewController.modalViewController;
        }
        return topViewController;
    

    }

    【讨论】:

      猜你喜欢
      • 2013-11-12
      • 1970-01-01
      • 1970-01-01
      • 2011-12-03
      • 1970-01-01
      • 2016-02-03
      • 2016-06-08
      • 1970-01-01
      • 2011-12-11
      相关资源
      最近更新 更多