我試圖刪除放置在地圖上的自定義註釋。問題是,爲了刪除該註釋,用戶必須按兩次我所做的刪除按鈕。這是刪除註釋的代碼行,[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