ios通知“死”对象 [英] ios notifications to "dead" objects

查看:61
本文介绍了ios通知“死”对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有许多UIViews进入视野,然后离开视野并被闲置。但是,我相信他们中的一些人即使在他们离开后仍然会收到通知,这会导致问题。

I have a number of UIViews coming into view, then going out of view and being unused. However, I believe some of them are still receiving notifications even after they are gone wich is causing problems.

在UIView父容器上:

On the UIView "parent" container:

if(self._content != nil && [self._content respondsToSelector:@selector(presentMe:)]) {
    [self._content presentMe:NO];
}

在UIView孩子上:

On the UIView "child":

[[NSNotificationCenter defaultCenter] <-- EXC_BAD_ACCESS (code=1, address=0x70000008
 postNotificationName:PRESENTING 
 object:self 
 userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:prepareToEnter], PRESENTING, nil]];

Everything第一次工作,但如果我第二次启动相同的视图我得到一个EXC_BAD_ACCESS。这是不是意味着缺少某些东西?

Everything works the first time around, but if I launch the same view a second time I get an EXC_BAD_ACCESS. Doesn't that mean something is missing?

FYI this全部在ARC - xcode 4.3.2

推荐答案

如果您正在调用 addObserver 对于视图中的项目,您需要在dealloc期间调用 removeObserver 。即使使用ARC。

If you are calling addObserver for items in your view, you need to call removeObserver during dealloc. Even with ARC.

这篇关于ios通知“死”对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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