Frage

I am either brain damaged or I am lacking of some understending of NSNotificationCenter

The problem is that if I create an observer and in the next line will try to delete it like so:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(removeAllVisibleMapViews) name:@"ClearVisibleMaps" object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self forKeyPath:@"ClearVisibleMaps"];

I get

*** Terminating app due to uncaught exception 'NSRangeException', reason: 'Cannot remove an observer <MyApp 0x592db70> for the key path "ClearVisibleMaps" from <NSNotificationCenter 0x4e0fbb0> because it is not registered as an observer.'

I add and remove observer line after line just to make a point. In my code I will be using remove in the dealloc.

So any ideas why it does tell me that I didn't add and observer in the first place?

Keine korrekte Lösung

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top