显示另一个UIWindow的麻烦 [英] trouble with displaying another UIWindow
问题描述
我正在写一个iPad应用程序,我正试图在我的应用程序主窗口的顶部显示第二个 UIWindow
。我要做的主要是创建一个登录窗口(如何使用UISplitViewController提交登录?) ,似乎在这里创建第二个窗口可能是一个不错的选择。
I'm writing an iPad app, and I'm trying to display a second UIWindow
on top of the main window in my app. The main thing I'm trying to do is create a log in window (how to present a login, with UISplitViewController?), and it seems that creating a second window here might be a good option.
我做了一个非常简单的应用来试试这个。当用户点击按钮时,我正在尝试显示第二个窗口。这是代码:
I've made a very simple app to try this out. When the user hits a button, then I'm trying to show the second window. Here's the code:
- (IBAction)showOtherWindow:(id)sender {
UIWindow* otherWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
otherWindow.hidden = NO;
otherWindow.clipsToBounds = YES;
otherWindow.windowLevel = UIWindowLevelStatusBar;
otherWindow.backgroundColor = [UIColor redColor];
[otherWindow makeKeyAndVisible];
}
我期待在这里看到一个大红色的屏幕,但那不是'发生 - 没有任何改变。最后,我希望在顶部有一个较小的窗口。但是现在我只想看到一个窗口。
I'm expecting to see a big red screen here, but that doesn't happen - nothing changes. Ultimately, I'd like to have a smaller window floating on top. But right now I'd just like to see a window at all.
推荐答案
如果您使用的是ARC代码,那么您的窗口就是在 showOtherWindow:
返回后立即取消分配。尝试将 otherWindow
分配给持久对象中的ivar。
If you're in ARC code your window is getting deallocated immediately after showOtherWindow:
returns. Try assigning otherWindow
to an ivar in a persistent object.
这篇关于显示另一个UIWindow的麻烦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!