Search code examples
iosexc-bad-accessnsnotificationcenter

ios notifications to "dead" objects


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


Solution

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