0

我在别针上添加了观察者。有一个问题:当我点击一个图钉时,有时我会两次调用observeValueForKeyPath。我需要做什么?

annotationView.enabled = YES;
annotationView.animatesDrop = YES;
annotationView.pinColor = MKPinAnnotationColorRed,
annotationView.canShowCallout = YES;

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
    NSString *action = (NSString*)context;

if([action isEqualToString:@"ANSELECTED"])
{
    BOOL annotationAppeared = [[change valueForKey:@"new"] boolValue];
    MKAnnotationView *annotationView = (MKAnnotationView *)object;
    if ( [annotationView.annotation isKindOfClass:[RestaurantLocation class]] )
    {
        RestaurantLocation *annot = (RestaurantLocation *)annotationView.annotation;
        if (annotationAppeared) 
        {do something}}

}
4

0 回答 0