0

Is there a way to remove the last added Annotation?

j0k
  • 22,600
  • 28
  • 79
  • 90
MotoxX
  • 917
  • 1
  • 7
  • 13
  • See http://stackoverflow.com/questions/13017305/how-to-reorder-mkmapview-annotations-array and http://stackoverflow.com/questions/9539802/mkmapview-annotations-changing-losing-order?lq=1 for an explanation of why using the map view's annotations array won't always work. –  Nov 08 '12 at 13:03

1 Answers1

5

[self.mapView removeAnnotation:self.mapView.annotations.lastObject];

gotnull
  • 26,454
  • 22
  • 137
  • 203
HackyStack
  • 4,887
  • 3
  • 22
  • 28
  • 1
    If this solves your problem, be sure to mark as correct please. – HackyStack Nov 07 '12 at 21:45
  • 2
    unfortunatly this doesn't solve the problem, because the last object is the Userlocation. So I thought I remove the second last object but I found out, that this is not always the last added Annotation (no idea why). But I solved my problem now by just adding the annotation to an array and taking this for deleting the last annotation. But nevertheless thanks for your help! – MotoxX Nov 08 '12 at 07:40