目标C语言 iPad MapKit -重新选择一个引脚不工作



我有以下问题:

我的地图上有一些大头针。触摸后,一个自定义弹出窗口打开并显示信息。

我的问题是,如果你选择相同的引脚两次,弹出框不打开,你必须触摸另一个或点击地图上的一些地方。

我的代码如下:
- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation{
    MKAnnotationView* annotationView = nil;
    CPPointOfInterest *myAnnotation = (CPPointOfInterest*) annotation;
    if ([myAnnotation isKindOfClass:[MKUserLocation class]] || myAnnotation.poi_id <= 0) {
        return nil;
    } else {
        NSString* identifier = @"Pin";
        MKPinAnnotationView* annView = (MKPinAnnotationView*)[mv_map dequeueReusableAnnotationViewWithIdentifier:identifier];
        if(nil == annView) {
            annView = [[[MKPinAnnotationView alloc] initWithAnnotation:myAnnotation reuseIdentifier:identifier] autorelease];
        }
        [annView addObserver:self
                  forKeyPath:@"selected"
                     options:NSKeyValueObservingOptionNew
                 context:@"GMAP_ANNOTATION_SELECTED"];
        if(self.nearest_poi == myAnnotation) {
            annView.pinColor = MKPinAnnotationColorGreen;
        } else {
            annView.pinColor = MKPinAnnotationColorRed;
        }
        annView.animatesDrop = YES;
        annotationView = annView;
        [annotationView setEnabled:YES];
        [annotationView setCanShowCallout:NO];
        return annotationView;
    }
}

观察者:

- (void)observeValueForKeyPath:(NSString *)keyPath
                      ofObject:(id)object
                        change:(NSDictionary *)change
                       context:(void *)context{
    NSString *action = (NSString*)context;
    if([action isEqualToString:@"GMAP_ANNOTATION_SELECTED"]){
        BOOL annotationAppeared = [[change valueForKey:@"new"] boolValue];
        if (annotationAppeared) {
            // show popup
            } 
    }
}

我也尝试了didSelectAnnotationView方法,这也只适用于第一次点击事件。

我已经找了几个小时了,但是什么也没找到…:/

有没有人知道我这个问题的解决方法,请给我一个提示…

谢谢大家!马修

您必须通过mapView取消选中注释,然后才能再次选中它。尝试以下操作:

-(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
[mapView deselectAnnotation:view.annotation animated:NO];
}

我正在使用一个弹出窗口来显示信息:

- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController
{
    if (popover)
    {
        [popover release];
        popover = nil;
    }
    LocatorSearchDealer *dealer = [[mapView selectedAnnotations] objectAtIndex:0];
    //without this line I cannot immediately reselect the same annotation.
    [mapView deselectAnnotation:dealer animated:NO];
}

相关内容

最新更新