I have an array with over 200 objects, and I'm trying to loop through each of them.
Each object will have a yes / no field, and I want to display a different color marker, depending on this yes / no value.
From what I see, it happens when my loop goes through each object first, and then the whole annotation is added to the end for each object.
Since I am checking inside my loop through an array with a value of yes no, when the whole annotation is added to my map, it will use the value yes / no from the last object in the array when it goes to the graph for everything.
How to do this so that the marker is different depending on the yes / no value for each individual element?
My code
for (i = 0; i < [appDelegate.itemArray count]; i++) {
item_details *tempObj = [appDelegate.itemArray objectAtIndex:i];
location.latitude = [tempObj.lat floatValue];
location.longitude = [tempObj.lon floatValue];
current_yesno = tempObj.yesno;
MapViewAnnotation *newAnnotation = [[MapViewAnnotation alloc]initWithTitle:tempObj.name andCoordinate:location];
[self.mapView addAnnotation:newAnnotation];
[newAnnotation release];
}
with my annotation code as follows
- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation{
MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"currentloc"];
if(current_yesno == YES){
annView.pinColor = MKPinAnnotationColorGreen;
}
else
{
annView.pinColor = MKPinAnnotationColorRed;
}
annView.animatesDrop=NO;
annView.canShowCallout = YES;
annView.calloutOffset = CGPointMake(-5, 5);
return annView;
}
current_yesno .h .