确定控制器的类型 - MonoTouch

发布于 2024-11-30 07:43:38 字数 349 浏览 0 评论 0原文

我需要找出当前应用程序中最顶层的控制器类型。

UIApplication.SharedApplication.KeyWindow.Subviews.Last().GetType()

返回 UIView。我知道当您使用 AddSubview() 方法时,您传递的是视图,而不是控制器。 Objective-C 有 IsKindOfClass 方法,但我真正尝试做的是当用户按下主页按钮时,如果电影播放器​​控制器位于顶部,我想关闭它。据我所知,我唯一可以这样做的地方是应用程序委托中的 OnResignActivation() 方法。

先谢谢你了,

干杯...

I need to find out the type of controller which is currently topmost in application.

UIApplication.SharedApplication.KeyWindow.Subviews.Last().GetType()

returns UIView. I'm aware that when you use AddSubview() method, you pass View, not the Controller.
Objective-C has IsKindOfClass method, but what I really try to do is when user presses home button, if movieplayer controller is on top, I want to dismiss it. The only place for me to do it is OnResignActivation() method in app's delegate as far as I know.

Thank you in advance,

Cheers...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小耗子 2024-12-07 07:43:38

你所说的“最上面”是什么意思?如果您正在谈论模态显示的控制器,您应该真正知道顶部是什么,因为您正在呈现控制器。 :-)

所以你可以保留对当前呈现的控制器的引用(例如在 AppDelegate 中)。然后你就会知道你所展示的是什么。

您还可以检查呈现视图控制器 ModalViewController 属性。它将引用当前以模态方式呈现的控制器(如果没有,则为 NULL)。
然后,您可以检查 if(oMyController.ModalViewController is MPMoviePlayerController) { /* do某些操作,如解雇 */}

但是要关闭模态呈现的控制器,您甚至不必知道它是什么。只需调用呈现控制器的 DismissModalViewControllerAnimated(bool) 方法,模态显示的任何内容都会消失。

What do you mean by the "topmost"? If you are talking about modally shown controllers, you should really know what's on top because you are presenting the controllers. :-)

So you could keep a reference to the controller you are currently presenting (in AppDelegate e.g.). You will then know what you are showing.

You can also check the presenting view controllers ModalViewController property. It will have a reference to the controller that is currently presented modally (or NULL, if none).
You can then check if(oMyController.ModalViewController is MPMoviePlayerController) { /* do something, like dismissal */}.

But to dismiss a modally presented controller you do not even have to know what it is. Just call the presenting controller's DismissModalViewControllerAnimated(bool) method, and whatever has been shown modally will be gone.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文