Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 我在大头针上加了一个观察者。有一个问题:有时我会得到双重调用observeValueForKeyPath_Iphone_Observer Pattern_Mkannotation_Mkannotationview - Fatal编程技术网

Iphone 我在大头针上加了一个观察者。有一个问题:有时我会得到双重调用observeValueForKeyPath

Iphone 我在大头针上加了一个观察者。有一个问题:有时我会得到双重调用observeValueForKeyPath,iphone,observer-pattern,mkannotation,mkannotationview,Iphone,Observer Pattern,Mkannotation,Mkannotationview,我在大头针上加了一个观察者。有一个问题:当我点击一个pin时,有时我会得到双重调用observeValueForKeyPath。我需要做什么 annotationView.enabled = YES; annotationView.animatesDrop = YES; annotationView.pinColor = MKPinAnnotationColorRed, annotationView.canShowCallout = YES; - (void)observeValueForKe

我在大头针上加了一个观察者。有一个问题:当我点击一个pin时,有时我会得到双重调用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}}

}

您正在观察哪个关键路径?为什么不使用didSelectAnnotationView委托方法?