无法在iOS中删除自定义注释

时间:2011-11-21 13:58:25

标签: iphone objective-c ios ipad mapkit

我正在尝试删除放置在地图上的自定义注释。问题是,为了删除该注释,用户必须按下我制作的删除按钮两次。这是删除注释[mv removeAnnotation:[mv.selectedAnnotations objectAtIndex:0]]的代码行。我几乎是肯定的,默认情况下我的当前位置(MKUserLocation)始终是数组中的第一个注释,这就是我必须按两次删除的原因。我是在正确的轨道上吗?任何建议将不胜感激。

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view{
NSLog(@"\n\n\n################################\nANNOATION SELECTED\n################################");



_currentAnnotation = view.annotation;
[self zoomOnAnnotation:_currentAnnotation];

 NSLog(@"selectedannotationview is %@", _currentAnnotation);

[viewLoadingCover setHidden:FALSE];
[actIndLoading startAnimating];
//Annotation *currentAnnotation = view.annotation;
currentAnnoView = view;
//if (isLoadingCallout) {
    [self getCurrentMapDataWithLatitute:_currentAnnotation.coordinate.latitude Longitute:_currentAnnotation.coordinate.longitude];
//}


if ([view.annotation isEqual:mapView.userLocation])
{
    isUser = YES;
    //NSLog(@"##### yes this is user location annotation");
    if (!view.rightCalloutAccessoryView) {
        //NSLog(@"##### yes view.rightCalloutAccessoryView is NIL");
        mapView.userLocation.title = @"Loading...";
        mapView.userLocation.subtitle = @" ";
        //NSLog(@"##### cityAndState(subtitle) = %@", cityAndState);
        //[[mapView userLocation] setSubtitle:[NSString stringWithString:cityAndState]];
        userButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        view.rightCalloutAccessoryView = userButton;
        [userButton addTarget:self action:@selector(UIButton:) forControlEvents:UIControlEventTouchUpInside];
        NSLog(@"userlocation selected---------------------------%@", cityAndState);
    }

    reverseG= [[MKReverseGeocoder alloc] initWithCoordinate:mapView.userLocation.coordinate];
    reverseG.delegate = self;
    [reverseG start];
}
else
{
    isUser = NO;
}

}

2 个答案:

答案 0 :(得分:1)

我建议使用NSLogging mv.selectedAnnotations来查看那里发生了什么。当计数的> 1快速证明你的理论是对还是错时,不会删除索引1处的注释而不是0?

答案 1 :(得分:0)

您是否对委托方法MKMapView

感兴趣?
- (Void) mapView: (MKMapView *) mapView didSelectAnnotationView: (MKAnnotationView *) view;
- (Void) mapView: (MKMapView *) mapView didDeselectAnnotationView: (MKAnnotationView *) view;

通过它们,您将知道选择或取消选择的注释。