不返回窗口
我需要向 iPhone 上的窗口添加一个视图,因此我尝试执行以下操作:[[UIApplication sharedApplication] windows]
,但该数组似乎只包含一个窗口。
谁能告诉我我没有写什么/我需要做什么?
I need to add a view to window on iPhone, so i tried to do this: [[UIApplication sharedApplication] windows]
, but it seams that the array contains only one window.
Can anyone tell me what i'm not doing write/what i need to do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
尝试
如果您想找到您的应用程序的窗口。
try
if you want to find your app's window.
您的 AppDelegate 类将保存该窗口(作为属性)。每个应用程序只能获得一个窗口。在大多数情况下,您应该只从 AppDelegate 直接将视图添加到窗口 - 对于正常的子视图管理,请使用 viewControllers。
Your AppDelegate class will hold the window (as a property). You only get one window per application. In most cases you should only add views directly to the window from the AppDelegate -- for normal subview management, use viewControllers.
嗯,我发现了问题。实际上,如果设置不正确,
[[UIApplication sharedApplication] windows]
仅返回一个窗口。尽管如此,[[UIApplication sharedApplication] keyWindow]
仍会抛出异常。这是因为当
MPVideoPlayerController
开始播放时,它开始创建一个新窗口,但是,可能不会立即完成这项工作。它几乎是立即创建的,但不是立即创建的。Well, I found the problem. Actually conditions where not set correct,
[[UIApplication sharedApplication] windows]
returned only one window. Still,[[UIApplication sharedApplication] keyWindow]
throw an exception.It was because When
MPVideoPlayerController
starts playing, it starts creating a new window, but, probably does not finish this job immediately. It is created ALMOST immediately, but not immediately.你可以做这样的事情。
You could do something like this.