"[CALayer版本]:发送到已释放实例的消息"解雇模态视图控制器时 [英] "[CALayer release]: message sent to deallocated instance" when dismissing modal view controller

查看:62
本文介绍了"[CALayer版本]:发送到已释放实例的消息"解雇模态视图控制器时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近几天,我一直在为此苦苦挣扎,但找不到任何解决方案,因此请您提出建议.

I've been struggling with this for last few days and I cannot find any solution, so I ask you for advice.

我有两个UIViewControllers:NewPostUIViewController和SettingsUIViewController.在第二个字段中,我有一个字段:

I have two UIViewControllers: NewPostUIViewController and SettingsUIViewController. In the second one I have a field:

id<SettingsUIViewControllerDelegate> delegate

第一个实现协议

SettingsUIViewControllerDelegate

按下按钮时,NewPostUIViewController中将执行以下代码:

When a button is pressed the following code is executed in NewPostUIViewController:

SettingsUIViewController *settingsUIViewController  = [[SettingsUIViewController alloc] initWithNibName:@"SettingsView" bundle:nil]; 
settingsUIViewController.title = NSLocalizedString(@"Settings", @"Settings view title");
settingsUIViewController.delegate = self; 
[self presentModalViewController:settingsUIViewController animated:YES];
[settingsUIViewController release];

当我想解散我调用的SettingsUIViewController时(SettingsUIViewController中的代码):

when I want to dismiss SettingsUIViewController I call (code in SettingsUIViewController):

[delegate settingsAreDone:sender];

和settingsAreDone看起来如下(NewPostUIViewController中的代码):

and settingsAreDone looks following (code in NewPostUIViewController):

    [self dismissModalViewControllerAnimated:YES];

全部结论如下:

[CALayer release]: message sent to deallocated instance 0x5a76840

我试图通过在两个视图控制器的release方法中设置一个断点来调试代码,但是这些方法经常被调用,以至于很难说出导致此问题的原因.

I tried to debug the code by setting a breakpoint in the release methods of both view controllers, but these methods are called so often that it's hard to say what can be the cause of this problem.

有什么想法吗?

推荐答案

首先,您收到的错误并不表示-release已发送到视图控制器,因此视图控制器中的断点将无济于事.过度释放发生在CALayer上,这很可能是模态动画的一部分.

First, the error you're getting isn't indicating that -release is being sent to a view controller, so breakpoints in your view controllers won't help. The over-release is happening on a CALayer, which is likely part of the modal animation.

首先,我们从有关委托的一些基础知识开始.对于这个原因,我并不感到满意,但是您应该始终从简单的基础开始.应该为您的SettingsUIViewController委托属性分配属性,而不是保留它,因此避免了保留循环.这可能已经是正确的,但是如果不是这样,您可能会遇到对象存在时间超出预期的情况(这样,在目标消失后可以发送消息).同样,可能不是问题,但易于检查且易于修复.

First, we start with some basics about the delegate. I don't feel great about this being the cause, but you should always start with the easy basics. Your SettingsUIViewController delegate property should be assign, not retain, so you avoid retain loops. That's probably correct already, but when it's not, you can wind up with cases where objects exist longer than you expect them to (and so can send messages after their targets have gone away). Again, probably not the issue, but easy to check and easy to fix.

接下来,您应该查看崩溃时的堆栈跟踪.谁在呼叫[CALayer release]?一个可能的原因是拥有的视图控制器在动画停止之前被释放.关闭设置控制器时,是否立即关闭NewPost控制器?

Next, you should look at the stack trace at the crash. Who is calling [CALayer release]? A possible cause is that the owning view controller gets released before the animation stops. When you close the settings controller, do you immediately close the NewPost controller?

这篇关于"[CALayer版本]:发送到已释放实例的消息"解雇模态视图控制器时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆