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