如何使用UIApplication获取我的UIWindow? [英] how to get my UIWindow using UIApplication?

查看:132
本文介绍了如何使用UIApplication获取我的UIWindow?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只有一个窗口,我试过

I have only one window and I tried

UIWindow* mWindow = [[UIApplication sharedApplication] keyWindow];

但这返回为零。

I还试过:

UIWindow* mWindow = (UIWindow*)[[UIApplication sharedApplication].windows objectAtIndex:0];

但是当我试图打印出来时,这引发了异常并关闭了应用程序

But this raised an exception and the app closed, when I tried to print out

[[UIApplication sharedApplication].windows count]

它打印0

注意:我将它放在我唯一的视图控制器的viewDidLoad方法中,这完全是一个新的基于iPad View的应用程序所以我什么都没改变,只是试图获得窗口

Note: I am putting this in my only view controller's viewDidLoad method and this is completely a new iPad View Based Application so I changed nothing, just trying to get the window

请帮助我获取此对象

推荐答案

如果您的主窗口是AppDelegate的插座(应该是这种情况),您可以直接使用

If your main window is an outlet of your AppDelegate (which should be the case), you may simply use

MyAppDelegate* myDelegate = (((MyAppDelegate*) [UIApplication sharedApplication].delegate));
[myDelegate.window ...]

这篇关于如何使用UIApplication获取我的UIWindow?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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