我试图删除放置在地图上的自定义注释。问题是,为了删除该注释,用户必须按两次我所做的删除按钮。这是删除注释的代码行,[mv removeAnnotation:[mv.selectedAnnotations objectAtIndex:0]]
。我几乎肯定,默认情况下我的当前位置(MKUserLocation)始终是数组中的第一个注释,这就是为什么我必须按删除两次。我在正确的轨道上吗?任何意见,将不胜感激。在iOS中删除自定义注释时遇到问题
- (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;
}
}
感谢Aliaksandr,我发布了我的didSelectedAnnotationView。我认为我已经钉住了,因为我发送了SelectedAnnotation,但由于某种奇怪的原因,它仍然需要2次尝试。 – user1042402