Observer never gets removed from NSNotificationCenter
I'm adding a view controller as an observer for
UIKeyboardWillShowNotification notification.
I have this code in my viewDidLoad:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
And in my dealloc:
[[NSNotificationCenter defaultCenter] removeObserver:self];
The observer is not being removed even though dealloc is called when the
view controller is closed. So when I open it for the second time,
NSNotificationCenter will attempt to notify the old object, which is
released, and the app crashes.
I have seen several questions here on StackOverflow about this particular
problem, but non of the answers works for me.
I've tried removing the observer in viewWillDisappear and viewDidDisappear
but the same problem happens.
I'm using ARC.
No comments:
Post a Comment