本文介绍了get“EXC_BAD_ACCESS”当尝试dismissModalViewController时,父视图控制器已经被viewDidUnload的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为MainView的视图控制器,它将调用

I have a view controller named "MainView", it will call

[self presentModalViewController:playView animated:NO];

可插入PlayView视图控制器。

to insert a "PlayView" view controller.

当应用程序在PlayView运行时,如果接收到applicationDidReceiveMemoryWarning消息,它将调用MainView的viewDidUnload函数并释放MainView对象。在这一刻,PlayView仍然活着。每一件事情都很好,直到用户点击一个按钮离开PlayView,它(PlayView)将调用:

When app is running at PlayView, if receiving an applicationDidReceiveMemoryWarning message, it will call MainView's viewDidUnload function and release the MainView object. In this moment, the PlayView is still alive. Every thing is fine until user click a button to leaving the PlayView, it(PlayView) will call:

[self dismissModalViewControllerAnimated:NO];

然后应用程序崩溃,接收到EXC_BAD_ACCESS错误消息...
原因是MainView对象消失了,当PlayView想要关闭自己时,它找不到合适的ViewController来呈现。

Then the application is crashed with receiving 'EXC_BAD_ACCESS' error message...I think the reason is that MainView object is gone, when PlayView want to dismiss itself, it can't find a suitable ViewController to present.

如何解决这个问题? T_T

How to fix this problem? T_T

PS。

推荐答案

我认为问题是与您的 MainView 。它有一些出口或属性指向视图(位于主视图)。内存警告 MainView.view 已卸载(因此它释放其子视图),如果您没有保留它们&没有将它们设置为nil,他们现在指向不存在的对象。所以你应该在viewDidUnload方法中将它们全部设置为nil。

I suppose the problem is with your MainView. It has some outlets or properties that point to views (that lay on the main view). After memory warning MainView.view is unloaded (so it releases its subviews) and if you haven't retained them & haven't set them to nil, they are now pointing to notexisting objects. So you should set them all to nil in viewDidUnload method.

这篇关于get“EXC_BAD_ACCESS”当尝试dismissModalViewController时,父视图控制器已经被viewDidUnload的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-13 23:21