UINavigationController 应用程序崩溃并出现错误消息:“无法从没有窗口的视图中呈现弹出窗口。”

发布于 2024-11-03 07:13:40 字数 760 浏览 5 评论 0原文

在我的导航应用程序中,当执行以下步骤时,应用程序总是崩溃并显示错误消息“无法从没有窗口的视图中呈现弹出窗口”

第 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月光色 2024-11-10 07:13:40

这里没什么可说的,但听起来你的导航控制器逻辑在某个地方是错误的。我可能会生成一个带有第二个视图控制器的新的基本导航控制器项目,确保您可以使用它来回导航并与您的项目进行比较。如果删除弹出框,一切正常吗?

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文