Dragging MKPinAnnotationView throws error
I have an AddressAnnotation class that conforms to the MKAnnotation class. I use the MKReverseGeocoderDelegate methods to get the address from the user's location. In that delegate, I drop the pin. I set the pin to be draggable, and when the following method is called, I start the reverse geocoder again.
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view didChangeDragState:(MKAnnotationViewDragState)newState fromOldState:(MKAnnotationViewDragState)oldState {
if (newState == MKAnnotationViewDragStateEnding) {
CLLocationCoordinate2D newCoordinate = view.annotation.coordinate;
MKReverseGeocoder *reverseGeocoder = [[MKReverseGeocoder alloc] initWithCoordinate:newCoordinate];
reverseGeocoder.delegate = self;
[reverseGeocoder start];
}
}
It works for about 3 pin drags, until I get the following error. I'm not sure what it means or what is going on. Any help would be appreciated. Thanks!
"An instance 0x1b7ac0 of class AddressAnnotation was deallocated while key value observers were still registered with it. Observation info was 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:开发者_如何学Python"
It sounds like you created an MKAnnotation subclass called AddressAnnotation. One class is observing a member of this class's properties with key-value observing and that instance of AddressAnnotation was deallocated without removing the observer. I think you can fix this by running
- (void)removeObserver:(NSObject *)anObserver forKeyPath:(NSString *)keyPath
before the AddressAnnotation is released.
精彩评论