UINavigationController 应用程序崩溃并出现错误消息:“无法从没有窗口的视图中呈现弹出窗口。”
在我的导航应用程序中,当执行以下步骤时,应用程序总是崩溃并显示错误消息“无法从没有窗口的视图中呈现弹出窗口”
第 1 步:点击 RootViewController
中的一行将推送到 < code>detailsViewController,点击detailsViewController中的按钮显示一个popOverController
,它成功了!
Step2:点击backButton会弹出到RootViewController
,再次执行Step1,崩溃了!
下面的代码将打印窗口的描述:
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
NSLog(@"%@", self.view.window);
}
按钮的操作 Step1 将打印窗口,Step2 将打印 nil:
- (void)btn_click:(id)sender {
NSLog(@"%@", self.view.window);
[self._popOver presentPopoverFromRect:[sender frame] inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
那么,我错过了什么?
In my navigation application, when step as follows, the app always crashed with error message "Popovers cannot be presented from a view which does not have a window"
Step1: Tap a row in RootViewController
will push to detailsViewController
, tap button in detailsViewController to show a popOverController
, it worked!
Step2: Tap backButton will pop to RootViewController
, do Step1 again, Crashed!
Below code will print the window's description all right:
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
NSLog(@"%@", self.view.window);
}
Button's action Step1 will print the window, Step2 will print nil:
- (void)btn_click:(id)sender {
NSLog(@"%@", self.view.window);
[self._popOver presentPopoverFromRect:[sender frame] inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
So, what I was missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这里没什么可说的,但听起来你的导航控制器逻辑在某个地方是错误的。我可能会生成一个带有第二个视图控制器的新的基本导航控制器项目,确保您可以使用它来回导航并与您的项目进行比较。如果删除弹出框,一切正常吗?
not much to go on here, but it sounds like your navigation controller logic is wrong somewhere. I'd probably generate a new basic navigation controller project with a second view controller, make sure you can navigate back and forth with it and compare to your project. If you remove the popover, everything works?