I have MKMap with around 190 custom pins. I would like to change pin image according to the boolean values. But I have made static boolean and in -(void)Map, I get data from Parse and also all boolean values. When I use If/Else in delegate method for custom pins, all booleans went FALSE.
-(void)Map{
CLLocation *userLoc = self.mapView.userLocation.location;
CLLocationCoordinate2D userCoordinate = userLoc.coordinate;
NSLog(@"user latitude = %f",userCoordinate.latitude);
NSLog(@"user longitude = %f",userCoordinate.longitude);
self.mapView.delegate=self;
NSMutableArray* annotations=[[NSMutableArray alloc] init];
NSMutableArray *title = [self.itemss valueForKey:@"title"];
NSMutableArray *subtitle = [self.itemss valueForKey:@"subtitle"];
NSMutableArray *latitude = [self.itemss valueForKey:@"Lati"];
NSMutableArray *longitude = [self.itemss valueForKey:@"Long"];
NSMutableArray *gold = [self.itemss valueForKey:@"clubPurchased"];
NSLog(@"%@", latitude);
NSLog(@"%@", longitude);
for (int i = 0; i < [title count]; i++){
NSLog(@"%lu", (unsigned long)title.count);
double lat = [[latitude objectAtIndex:i] doubleValue];
double lng = [[longitude objectAtIndex:i] doubleValue];
NSString *T = [title objectAtIndex:i];
NSString *TT = [subtitle objectAtIndex:i];
mine = [[gold objectAtIndex:i] boolValue];
NSLog(@"BOOL:%hhd", mine);
CLLocation *towerLocation = [[CLLocation alloc] initWithLatitude:lat longitude:lng];
[annotations addObject:towerLocation];
CLLocationCoordinate2D coord = [[annotations lastObject] coordinate];
PlacePin * myAnnotation1=[[PlacePin alloc] init];
myAnnotation1.coordinate=coord;
myAnnotation1.title=T;
myAnnotation1.subtitle=TT;
[self.mapView addAnnotation:myAnnotation1];
[SVProgressHUD dismiss];
}
}
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
NSLog(@"welcome into the map view annotation");
// if it's the user location, just return nil.
if ([annotation isKindOfClass:[MKUserLocation class]])
return nil;
// try to dequeue an existing pin view first
static NSString* AnnotationIdentifier = @"AnnotationIdentifier";
MKAnnotationView* pinView = [[MKAnnotationView alloc]
initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier];
if (mine){
pinView.image = [UIImage imageNamed:@"Iconn"];
NSLog(@"TRUE");
} else {
NSLog(@"FALSE");
pinView.image = [UIImage imageNamed:@"Iconn_gold"];
}
pinView.canShowCallout=YES;
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton setTitle:annotation.title forState:UIControlStateNormal];
[rightButton addTarget:self
action:@selector(showDetails:)
forControlEvents:UIControlEventTouchUpInside];
pinView.rightCalloutAccessoryView = rightButton;
return pinView;
}