确定控制器的类型 - MonoTouch
我需要找出当前应用程序中最顶层的控制器类型。
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你所说的“最上面”是什么意思?如果您正在谈论模态显示的控制器,您应该真正知道顶部是什么,因为您正在呈现控制器。 :-)
所以你可以保留对当前呈现的控制器的引用(例如在 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.