我正在写一个iPad应用程序,我正试图在我的应用程序的主窗口顶部显示第二个UIWindow.我要做的主要是创建一个登录窗口(
how to present a login,with UISplitViewController?),似乎在这里创建第二个窗口可能是一个不错的选择.
我做了一个非常简单的应用程序试试这个.当用户点击按钮时,我正试图显示第二个窗口.这是代码:
- (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]; }
我期待在这里看到一个大红色屏幕,但这不会发生 – 没有任何变化.最后,我想让一个较小的窗户浮在上面.但是现在我只想看到一个窗口.
解决方法
如果您使用的是ARC代码,那么在showOtherWindow:返回后,您的窗口将立即被释放.尝试将otherWindow分配给持久对象中的ivar.