ios notifications to “dead” objects

感情迁移 提交于 2019-12-22 05:34:11

问题


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.

On the UIView "parent" container:

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

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 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 is all in ARC - xcode 4.3.2


回答1:


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



来源:https://stackoverflow.com/questions/10323087/ios-notifications-to-dead-objects

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!