I think I got it.

for (id <MKAnnotation> annotation in mapView.annotations) {                     
                [[mapView viewForAnnotation:annotation] removeObserver:self 
forKeyPath:@"selected"];
}

Regards,

Phil


On Sep 11, 2010, at 7:49 AM, Philip Vallone wrote:

> Hi,
> 
> I am trying to add a KVO for my MKPinAnnotationView class.  In my 
> MapViewController which has an instance of a MKMapView, I have the following 
> code:
> 
> - (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views {
> 
>    for (MKAnnotationView *anAnnotationView in views) {
> 
>        [anAnnotationView addObserver:self
>                           forKeyPath:@"selected"
>                              options:NSKeyValueObservingOptionNew
>                              context:MAP_ANNOTATION_SELECTED];
>    }
> 
> }
> 
> - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object 
> change:(NSDictionary *)change  context:(void *)context{
>       
>    NSString *action = (NSString*)context;
>       NSLog(@"Selected");
>    if([action isEqualToString:MAP_ANNOTATION_SELECTED]){
>               // do something
>               
>       }
> }
> 
> 
> In my AnnotationView I try to remove the observer:
> 
> - (void)dealloc {
>       
>       [self removeObserver:self forKeyPath:@"selected"];
>       
>       [super dealloc];
> }
> 
> My MapViewController is a UIViewController. When I add some 
> MKAnnotationViews, and the view is removed, I get the following error:
> 
> An instance 0x6b778b0 of class MKPinAnnotationView 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:
> <NSKeyValueObservationInfo 0x6e39030> (
> <NSKeyValueObservance 0x6b641e0: Observer: 0x6e32220, Key path: selected, 
> Options: <New: YES, Old: NO, Prior: NO> Context: 0x1722c, Property: 0x6b77ff0>
> 
> 
> 
> I am a bit confused. I am not sure how to remove the observer...
> 
> Thanks for the help,
> 
> Phil
> 
> 
> _______________________________________________
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/cocoa-dev/philip.vallone%40verizon.net
> 
> This email sent to philip.vall...@verizon.net

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to