请协助解决 modalViewController 崩溃问题

发布于 2024-12-19 11:19:39 字数 1550 浏览 3 评论 0原文

当我通过以下方式关闭 ModalViewController 时,我的应用程序崩溃了:

[self.parentViewController dismissModalViewControllerAnimated:YES];

当用户单击 UINavigationController(“NavRoot”)的一个单元格时,会显示此模态视图控制器(“MVC”) - 这是其代码:

MVC *modalView = [[MVC alloc] initWithNibName:@"MVC" bundle:nil];
[self.navigationController presentModalViewController: modalView animated:YES];
[modalView release];         

加载的“modalView”仅包含 2 个对象:一个 UIWebView 对象和一个“DONE”按钮,单击该按钮时会通过以下方式解除:

[self.parentViewController dismissModalViewControllerAnimated:YES];

除了当我单击“DONE”时 -应用程序崩溃。

当我使用 NSZombies 运行 Instruments 时,我确实看到保留计数达到 -1,但我无法判断是什么导致了这种过度释放。

我发现解决问题的唯一方法是在“NavRoot”中添加“[modalView keep]”语句 - 这是 viewController 执行 modalView 的呈现:

MVC *modalView = [[MVC alloc] initWithNibName:@"MVC" bundle:nil];
[self.navigationController presentModalViewController: modalView animated:YES];
[modalView retain];  //  <<== new 'retain' statement
[modalView release];

或者只是从不首先释放 modalView:

MVC *modalView = [[MVC alloc] initWithNibName:@"MVC" bundle:nil];
[self.navigationController presentModalViewController: modalView animated:YES];
// commenting out the 'release':
// [modalView release];

这两个当我运行“Analyze”(“第 34 行分配的对象的潜在泄漏”...)时,选项会抛出标志,但它们确实解决了问题。 尽管如此,我还是担心这会导致该应用程序被苹果从应用程序商店中拒绝。

关于可能导致过度释放的原因有什么想法吗?或者我如何进一步尝试隔离/识别问题?

附上仪器/僵尸报告的图像: 在此处输入图像描述

My app is crashing when I dismiss a ModalViewController via:

[self.parentViewController dismissModalViewControllerAnimated:YES];

This modal view-controller ("MVC") is presented when a user clicks on one of the cells of a UINavigationController ("NavRoot") - here's the code for that:

MVC *modalView = [[MVC alloc] initWithNibName:@"MVC" bundle:nil];
[self.navigationController presentModalViewController: modalView animated:YES];
[modalView release];         

The "modalView" which is loaded contains only 2 objects: a UIWebView object and a "DONE" button, which when clicked-on does the dissmissing via:

[self.parentViewController dismissModalViewControllerAnimated:YES];

Except when I click on "DONE" - the app crashes.

When I run Instruments with NSZombies I do see the retain count reaches -1 but I can't tell what's causing this over-release.

The only thing I found which solves the problem is to either add a "[modalView retain]" statement in "NavRoot" - which is the viewController doing the presenting of modalView:

MVC *modalView = [[MVC alloc] initWithNibName:@"MVC" bundle:nil];
[self.navigationController presentModalViewController: modalView animated:YES];
[modalView retain];  //  <<== new 'retain' statement
[modalView release];

or just simply never releasing modalView in the first place:

MVC *modalView = [[MVC alloc] initWithNibName:@"MVC" bundle:nil];
[self.navigationController presentModalViewController: modalView animated:YES];
// commenting out the 'release':
// [modalView release];

Both of these options throw flags when I run "Analyze" ("Potential leak of an object allocated on line 34"...) but they do fix the problem.
Still, I worry about this causing the app to be rejected by Apple from the App Store.

Any ideas on what may be causing the over-release? Or how I might further try to isolate / identify the problem?

attaching an image of Instruments/Zombies report:
enter image description here

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

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

发布评论

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

评论(4

奢欲 2024-12-26 11:19:39

你使用的是 iOS 5 吗?当我将应用程序从 ios4 切换到 5 时,我遇到了同样的问题。

ParentViewController 现在称为presentingViewController,

但您可以做的是在模态视图中只需调用 [selfmissModalViewController] ,它应该自行解散。我不是 100% 对此了解,并且无法检查,因为我不在我的 mac 附近,但我记得在文档中读过它,

Are u using iOS 5? I had the same problem when I switched an app from ios4 to 5.

ParentViewController is now called presentingViewController

What you can do though is in your modal view just call [self dismissModalViewController] and it should dismiss itself. I'm not 100% about that and can't check as I'm not near my mac, but I recall reading it in the docs,

無處可尋 2024-12-26 11:19:39

如果你这样做

[self.navigationControllerpresentModalViewController: modalViewanimated:YES];

一样解雇它,

那么你应该像[self.navigationController DismissModalViewControllerAnimated:YES];

而不是

[ self.parentViewController DismissModalViewControllerAnimated:YES];

您想从哪里关闭视图?实际的modalView还是parentView?在我看来,您试图驳回已经被驳回并随后发布的模态视图。

If you do

[self.navigationController presentModalViewController: modalView animated:YES];

Then you should dismiss it like

[self.navigationController dismissModalViewControllerAnimated:YES];

Rather than

[self.parentViewController dismissModalViewControllerAnimated:YES];

Where are you trying to dismiss the view from? The actual modalView or the parentView? It seems to me that you are trying to dismiss a modal view that has already been dismissed and subsequently released.

少年亿悲伤 2024-12-26 11:19:39

要关闭 modalViewController,我只需执行:[selfmissModalViewControllerAnimated:YES];

To dismiss a modalViewController I simply just do: [self dismissModalViewControllerAnimated:YES];.

嘿咻 2024-12-26 11:19:39

[selfmissModalViewControllerAnimated:YES] 在 iOS 5 上不起作用。

我构建了一个在 iOS 4 上添加 presentingViewController 的类别。(它在 iOS 5 上禁用自身。)

只需包含2 个文件,并且可以无缝运行。

请参阅后向模态

我希望这对你和我一样有好处;它使您的代码更加干净!

[self dismissModalViewControllerAnimated:YES] does not work on iOS 5.

I have built a category that add presentingViewController on iOS 4. (It disables itself on iOS 5.)

Just include 2 files, and it works seamlessly.

Please see backward-modal.

I hope this benefits you as much as it does to me; It makes your code more clean!

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