我在mapView和用戶位置點上有很多註釋。然後,如果用戶點擊2秒。在地圖上,我添加了一些額外的選項。我需要通過按下按鈕從地圖中刪除最後添加的註釋。我如何刪除它而不刪除任何其他註釋?如何刪除剛添加的註釋?
- (void)addPin:(UILongPressGestureRecognizer*)recognizer {
if(UIGestureRecognizerStateBegan == recognizer.state) {
CGPoint tappedPoint = [recognizer locationInView:mapView];
CLLocationCoordinate2D locCoord= [mapView convertPoint:tappedPoint toCoordinateFromView:mapView];
MKPointAnnotation *annot = [[MKPointAnnotation alloc] init];
annot.coordinate = locCoord;
[self.mapView addAnnotation:annot];
}
if(UIGestureRecognizerStateChanged == recognizer.state) {
// Do repeated work here (repeats continuously) while finger is down
}
if(UIGestureRecognizerStateEnded == recognizer.state) {
// Do end work here when finger is lifted
}
}
見http://stackoverflow.com/questions/17892362/how-to-delete-the-last-annotation-on-a-mapview – Anna