2011-05-11 9 views
12

estoy bien cerebral dañado o me falta de alguna understending de NSNotificationCenterNSNotification removeObserver problema

El problema es que si se crea un observador y en la línea siguiente a tratar de eliminarla, así:

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

me sale

*** 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.' 

que agregar y quitar la línea de observación después de la línea sólo para hacer un punto. En mi código usaré quitar en el trato.

¿Alguna idea de por qué me dice que no agregué y observo en primer lugar?

Respuesta

24

Está eliminando el observador para keypath, no para el nombre de notificación. La eliminación debería ser algo como esto:

[[NSNotificationCenter defaultCenter] removeObserver:self 
               name:@"ClearVisibleMaps" 
               object:nil]; 
+1

gracias, por lo que es cierto que estoy con daño cerebral :-) jeje al menos hoy. – Cyprian

Cuestiones relacionadas