开发者

Determine type of controller - MonoTouch

开发者 https://www.devze.com 2023-03-29 12:13 出处:网络
I need to find out the type of controller which is currently topmost in application. UIApplication.SharedApplication.KeyWindow.Subviews.Last().GetType()

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开发者_JAVA百科 is OnResignActivation() method in app's delegate as far as I know.

Thank you in advance,

Cheers...


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消