0

I have registered for a notification in the superclass. The observer is handled in the subclass which calls the super implementation. Do I remove the observer in the dealloc of the superclass or subclass ?

VBK
  • 1,435
  • 1
  • 15
  • 34

2 Answers2

2

You should be removing the observer from the same class you registered for the notification.

rocky
  • 3,521
  • 1
  • 23
  • 31
  • I tried unregistering in the superclass. But I sometimes get crashes due to the view controller being nil in the notification handler. – VBK May 21 '13 at 03:53
  • And did you find out why the view controller was nil? – rocky May 21 '13 at 06:11
  • It happened on another users device. The crash report said [UIImageView navigationItem] - unable to respond to selector. That code was in the notification handler. That line was actually [self navigationItem]. So I think that view controller got deallocated at some point during the notification handler. But I am not sure what caused it. – VBK May 21 '13 at 06:28
1

I wrote a small class that will automatically remove registered notifications. You can find it at AutoRemoveObserver

GilroyKilroy
  • 847
  • 10
  • 17