iphone - remove Annotation removes random amount of annotations at a time -
i've got code erase annotations (pins) in mkmapview without erasing blue dot (userlocation). problem erasing pins i've added in seemingly random numbers. when it's called through ibaction removes first 5 click again removes next 3, next 2, last one.
when pressed need remove latest pin...etc. etc.
for (int = 0; < [mapview.annotations count]; i++ ) { if ([[mapview.annotations objectatindex:i] iskindofclass:[myannotation class]]) { [mapview removeannotation:[mapview.annotations objectatindex:i]]; } }
the problem modifying annotation
collection while iterating on it. @ every execution of loop, loop's termination condition [mapview.annotations count]
changes value. lead unforeseen behavior. should
- either put annotations want remove empty mutable array inside loop call
removeannotations:
array parameter after exit loop, - or count down annotation highest index 0.
Comments
Post a Comment