【问题标题】:check current view controller over screen in ios在 ios 的屏幕上检查当前视图控制器
【发布时间】:2012-10-06 13:17:19
【问题描述】:

我在 self 对象上展示了一个包含 UIViewController 的 UINavigationController,代码如下

  drawController = [[DrawImageViewController alloc] initWithNibName:nil bundle:nil];
[drawController setDrawControllerDelegateObject:self];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:drawController];
[self presentModalViewController:nav animated:YES];
[nav release];

但是在第二次调用上述代码之前,我想知道当前出现在屏幕上的视图控制器是否是 drawController。我正在使用以下代码

    if (drawController && [drawController isBeingPresented])

但它不适用于我,它也适用于 iOS 5.0,所以我被困在这里。请帮助我知道我应该如何知道当前出现在屏幕上的 UIViewController 属于哪个类以及 drawContoller 是否仍然出现在屏幕上?抱歉,如果有任何拼写错误。任何帮助将不胜感激。

感谢内哈·梅塔

【问题讨论】:

    标签: iphone ios ipad uiviewcontroller


    【解决方案1】:

    使用navigationController's visibleViewController propertyisKindOfClass method 了解top 上的内容:

    if([self.navigationController.visibleViewController isKindOfClass:[yourcontroller class]])
       //exists
    else
       //not exists
    

    【讨论】:

    • 这个错误非常小,但您需要在 self 周围包含 []。
    【解决方案2】:

    不是最漂亮的代码,但这应该可以工作:

    if ([self.presentedViewController isKindOfClass:[UINavigationController class]] &&
       ((UINavigationController *)self.presentedViewController).topViewController == drawController) {
       …
    

    【讨论】:

      【解决方案3】:

      检查UINavigationControllers visibleViewController 方法。

      有关文档,请参阅UINavigationController

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-09-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-08-13
        相关资源
        最近更新 更多