奇怪的 EXC_BAD_ACCESS 与 [selfmissModalViewControllerAnimated]

发布于 2024-12-11 08:58:25 字数 815 浏览 6 评论 0原文

在我的应用程序中,我以模式方式在视图之间切换。我的问题是,当我从第一个 viewController 移动到第二个 viewController 时,它可以工作。当我第一次忽略第二个视图时,这也有效。你说问题出在哪里?它来了。当我第二次从第一个视图控制器移动到第二个视图控制器时,它再次工作。正如它应该的那样。然而,当我第二次尝试关闭第二个 viewController 时,我收到了 EXC_BAD_ACCESS 错误

[self dismissModalViewControllerAnimated:YES];

为什么第二次会崩溃,而第一次却不会?

编辑一:

无论我切换到哪个视图控制器,都会发生此错误:

如果我从 A 移动到 B,然后返回 A,然后返回 B,然后尝试返回 A:崩溃 如果我从 A 移动到 C,然后回到 A,然后到 C,然后尝试返回到 A:再次崩溃

编辑二:

我使用以下代码创建/显示视图控制器:

MapView *controller = [[MapView alloc] initWithNibName:@"MapView" bundle:nil];

controller.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:controller animated:YES];

我应该在创建后释放该对象吗?

问题解决了。在使用模态视图之前,我在使用模态视图之前使用了有问题的代码行,但我忘记将其删除。赢。

In my app, I switch between views modally. My problem is, when I move from the first viewController to the second, it works. When I dismiss the second view for the first time, that also works. Where is the problem, you say? It's coming. When I move from the first viewController to the second a second time, it works again. Just as it should. Yet when I try to dismiss the second viewController the SECOND time, I get an EXC_BAD_ACCESS error on the

[self dismissModalViewControllerAnimated:YES];

line.

Why does it crash the second time, but never the first time?

EDIT ONE:

This error happens no matter which viewController I switch to:

If I move from A to B, then back to A, then to B, then try to go back to A: crash
If I move from A to C, then back to A, then to C, then try to go back to A: crash again

EDIT TWO:

I create/show the view controller with this code:

MapView *controller = [[MapView alloc] initWithNibName:@"MapView" bundle:nil];

controller.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:controller animated:YES];

Should I be releasing this object after its creation?

Problem solved. Offending line of code was being used earlier for the transition I was using before I used modal views, and I forgot to remove it. Win.

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

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

发布评论

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

评论(1

守护在此方 2024-12-18 08:58:26

通常,EXC_BAD_ACCESS 错误意味着您正在尝试引用已释放的对象,即您过度释放了某些内容。检查一下您的内存管理,也许运行构建/构建和分析工具。

是的,您应该在以模态方式呈现视图控制器后调用[controller release];

Typically, an EXC_BAD_ACCESS error means you are trying to reference a deallocated object, i.e. you are over-releasing something. Check back through your memory management, maybe run the Build/Build and Analyze tool.

And yes, you should call [controller release]; after presenting the viewcontroller modally.

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