Tengo un ViewController (con un MKMapView) que se inserta, debido al NavigationController. Así que tengo una NavBar con un botón "Atrás". hacer clic en ese respaldo botón, me sale un error:iPhone - Una instancia de la clase ... está siendo desasignada mientras la observación del valor clave todavía está registrada con ella
2010-01-11 18:05:35.273 TestApp[147:207] An instance 0x1758f0 of class MKUserLocation is being deallocated while key value observers are still registered with it. Observation info is being leaked, and may even become mistakenly attached to some other object. Set a breakpoint on NSKVODeallocateBreak to stop here in the debugger. Here's the current observation info: ( Context: 0x0, Property: 0x17d600> ) Program received signal: “EXC_BAD_ACCESS”.
He método viewDidLoad implementado con un observador:
- (void)viewDidLoad {
mapView = (MKMapView*)self.view;
mapView.delegate = self;
mapView.mapType = MKMapTypeHybrid;
mapView.showsUserLocation = YES;
// ...
[mapView.userLocation addObserver:self forKeyPath:@"location" options:0 context:NULL];
[super viewDidLoad];
}
Mi dealloc:
- (void)dealloc {
[groupId release];
[[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
}
¿Alguien puede decirme qué sucede aquí? Hago clic en el botón Atrás en NavBar y luego entro en el método dealloc y luego vuelve al ViewController superior y arroja este error.
Muchas gracias de antemano & Atentamente.
esto funciona genial! ya no hay errores – Tim
Más específicamente, estaba combinando dos modelos de notificación diferentes: NSNotifications y KVO. (¡Aunque la solución de Brad es correcta!) –