问题
In one of my view controller, it adds itself as observer of UITextViewTextDidEndEditingNotification notification, like the following does
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(done:) name:UITextViewTextDidEndEditingNotification object:nil];
Now I am wondering - do I need to do the following when the view controller is dealloc'd
[[NSNotificationCenter defaultCenter] removeObserver:self];
回答1:
yes, you should always remove any observers when they're being dealloc'd. otherwise the notification center will keep references to the now-dealloc'd objects around and continue to try to forward notifications to them.
来源:https://stackoverflow.com/questions/8665575/is-removeobserver-necessary-on-dealloc