I'm developing an App where a farmer drops custom annotations ( pins with numbers ) at points of interest in his crop, emails a report with screenshot back to his office, and moves on to his next paddock.
Part of the code that sends the email include resetting properties and zeroing arrays and ivars etc. His first field works fine, but the numbering of the POI in all the fields that follow go haywire. The data represented by the errant pins are correct, just the pins themselves are not( more on that in a moment >>**).
So I've established that there is nothing wrong with anything leading up to a pin drop and I've cleared my annotations with:
[ self.mapView removeAnnotations:self.mapView.annotations];
The Apple docs mention that one also needs to implement this method in the reset:
[ self.mapView dequeueReusableAnnotationViewWithIdentifier:@"myAnnotation"];
because even though they've been cleared from the screen they are still present in memory. However that still does not fix my quandry. If I explicitly wipe my annotations out of existence with:
self.mapView.annotations = nil;
the problem still remains. Numbers on the annotation appear random in the 2nd and 3rd .. field. By logging to an onscreen textView I can see the array holding the correct values of the POI number. Something about CLLocation or MKAnnotation is still persisting somewhere. Nothing is in the Class Reference at Apple about how to reset CLLocationManager, so I presume it is done with a simple Start and Stop. My use of those are correctly balanced, so I'm not running multiple instances.
**>> Here's the snippet that decides what pin to drop, the action happens in the middle where commented
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation(id<MKAnnotation>)annotation
{
if([annotation isKindOfClass:[MKUserLocation class]])
return nil;
static NSString *identifier = @"myAnnotation";
MKAnnotationView * annotationView = (MKAnnotationView*)[self.mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
if (!annotationView)
{
annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
// standard stuff up to here
// findings build up as a score of each test point.
if (contentScore == 0)
{
// a green asterisk marker if no score was achieved
annotationView.image = [UIImage imageNamed:@"markerZero.png"];
} else {
// the marker number comes from idx in SiteCount Array
str = [NSString stringWithFormat:@"marker%d.png",siteCount[idx];
annotationView.image = [UIImage imageNamed:str];
}
} else {
annotationView.annotation = annotation;
}
return annotationView;
}
Currently the workaround is the fiddly job of taking it out of memory on the home screen and relaunching before beginning the next field. I could go back to using the red and green pins provided by the system but he's been spoiled by having numbers to cross-reference the report.
So where should I be looking? Who is the culprit? I suspect MKAnnonation but my knowledge has run out