iOS 编程:“超级dealloc”应用程序崩溃

发布于 2024-11-18 09:10:05 字数 619 浏览 4 评论 0原文

这是我第一次在这个网站上提问。作为一名业余开发人员,我总是在这个网站上找到我的问题的答案,但我找不到我当前问题的答案。

在我的 iPad 应用程序中,我从 rootView 调用一个新的 UIViewController:

DisplayTheMapViewController_iPad *root = [[DisplayTheMapViewController_iPad alloc] init];
displayTheMapViewController=root;
[[self navigationController] pushViewController:displayTheMapViewController animated:YES];
[root release];

当我从该视图返回到主视图时,应用程序崩溃(需要一分钟左右,直到那时一切正常,但它总是会发生),并显示自动释放池错误。

当我评论 [root release] 时,应用程序保持活动状态,但随后我遇到了一个不同的问题:在我第二次访问视图(不是第一次!)时,当调用在视图中放置弹出窗口的方法时,应用程序崩溃并我收到以下错误:

“无法从没有窗口的视图中呈现弹出窗口。”

我一定做错了什么。我预先感谢您的任何建议。

This is my first time asking a question in this site. as an amateur developer, I always found answers to my questions in this site, but I could not find one to my current problem.

In my iPad app I call a new UIViewController from the rootView:

DisplayTheMapViewController_iPad *root = [[DisplayTheMapViewController_iPad alloc] init];
displayTheMapViewController=root;
[[self navigationController] pushViewController:displayTheMapViewController animated:YES];
[root release];

When I go back from this view to the main view the application crashes (it takes a minute or so, and until then everything is normal, but it always happens), with an auto release pool error.

when I comment [root release] the app stays alive, but then I have a different problem: On my second visit to the view (not the first!) when a call a method that puts a popover in the view, the app crashes and I get the following error:

'Popovers cannot be presented from a view which does not have a window.'

I must do something wrong. I thank you in advance for any advice.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

兲鉂ぱ嘚淚 2024-11-25 09:10:05

这行代码有点令人费解:

displayTheMapViewController=root;

我猜 displayTheMapViewController 是一个实例变量?如果是这样,您将为其分配 root 权限,但不会保留 root 权限。当该控制器从导航堆栈中弹出时,导航控制器将释放它,导致它被释放,因为没有其他东西保留它。 displayTheMapViewController 将指向一个无效的对象。也许您的意思是:

self.displayTheMapViewController=root;

如果 displayTheMapViewController 属性 设置为保留其内容,那就可以防止上面的悬空指针问题。

This line is a bit puzzling:

displayTheMapViewController=root;

I'm guessing that displayTheMapViewController is an instance variable? If so, you're assigning root to it, but you're not retaining root. When that controller is popped off the navigation stack, the navigation controller will release it, causing it to be deallocated because nothing else has retained it. displayTheMapViewController will then point to an invalid object. Perhaps you meant to say:

self.displayTheMapViewController=root;

If the displayTheMapViewController property is set to retain its contents, that'd prevent the dangling pointer problem above.

夜灵血窟げ 2024-11-25 09:10:05

检查您的 DisplayTheMapViewController_iPad 类顶部底部是否忘记释放分配的对象。

Check your DisplayTheMapViewController_iPad class top bottom that you forgot to release a allocated object.

白衬杉格子梦 2024-11-25 09:10:05

您没有发布足够的代码来完全诊断问题,但我建议检查该行:displayTheMapViewController = root;。由于您没有保留 root,因此在从导航控制器中删除视图控制器后,displayTheMapViewController 将保持悬空状态。

至于当您不释放 root 并重新进入视图时会发生什么,我怀疑一旦您有第二个实例,这与 DisplayTheMapViewController_iPad 的内部结构有关。

You don't post enough code to fully diagnose the problem, but I would suggest checking the line: displayTheMapViewController = root;. Since you are not retaining root, displayTheMapViewController will be left dangling after the view controller is removed from the navigation controller.

As to what happens when you do not release root and reenter the view, I suspect this is something related to the internals of DisplayTheMapViewController_iPad once you have a second instance of it around.

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