确定视图是否在Popover视图中 [英] Determine if a view is inside of a Popover view

查看:106
本文介绍了确定视图是否在Popover视图中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在 UINavigationControllers 内的许多地方都有我们的应用程序使用的常见视图。偶尔 UINavigationController 是在popover视图中。现在我们放入导航控制器的视图会修改导航控制器的工具栏按钮,在某些情况下,还会使用我们创建的自定义按钮。如果视图在popoverview中,我们需要能够从 UIViewcontroller 本身找出来,这样我们才能显示正确颜色的按钮。

We have common views that we use in our application in many locations inside of UINavigationControllers. Occasionally the UINavigationControllers are inside of popover views. Now the views we put into the nav controllers modify their navigation controller's toolbar buttons and, in some cases, use custom buttons that we've created. We need to be able to figure out from the UIViewcontroller itself if the view is inside of a popoverview so we can display the correctly colored buttons.

我们可以使用 UIViewController.navigationController 从UIViewController轻松获取导航控制器参考,但似乎找不到任何东西 UIPopoverController

We can easily get the Navigation controller reference from the UIViewController, using UIViewController.navigationController, but there doesn't seem to be anything for finding a UIPopoverController.

有没有人对如何做到这一点有什么好主意?

Does anyone have any good ideas for how to do this?

谢谢!

推荐答案

我最近正在寻找一种方法来确定是否显示了视图在一个弹出窗口。这就是我想出的:

I was recently looking for a way to determine wether or not a view was being displayed in a popover. This is what I came up with:

    UIView *v=theViewInQuestion;        
    for (;v.superview != nil; v=v.superview) {
        if (!strcmp(object_getClassName(v), "UIPopoverView")) {
            NSLog(@"\n\n\nIM IN A POPOVER!\n\n\n\n");
        }

基本上你爬上视图的超级视图树,看它是否有任何超级视图一个UIPopoverView。这里要注意的是,UIPopoverView类是一个未记录的私有类。我依赖于类名在将来不会改变的事实。 YMMV。

Basically you climb the view's superview tree looking to see if any of its superviews is a UIPopoverView. The one caveat here is that the class UIPopoverView is an undocumented private class. I'm relying on the fact that the class name won't change in the future. YMMV.

在你的情况下:

theViewInQuestion =  theViewControllerInQuestion.view;

我有兴趣看看是否有其他人想出更好的解决方案。

I'd be interested to see if anyone else comes up with a better solution.

这篇关于确定视图是否在Popover视图中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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