Vote count:
0
I am trying to dynamically change the callout image based on json response.But only one image display for all callouts please help me how to do this
#pragma mark Map View Delegate Methods
method for view for annotation - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id )annotation { // If it's the user location, just return nil. if ([annotation isKindOfClass:[MKUserLocation class]]) return nil;
// Handle any custom annotations.
if ([annotation isKindOfClass:[MKPointAnnotation class]])
{
// Try to dequeue an existing pin view first.
MKAnnotationView *pinView = (MKAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:@"CustomPinAnnotationView"];
if (!pinView)
{
// If an existing pin view was not available, create one.
pinView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"CustomPinAnnotationView"];
pinView.canShowCallout = YES;
pinView.image = [UIImage imageNamed:@"pin.png"];
pinView.frame = CGRectMake(0, 0, 25, 30);
pinView.calloutOffset = CGPointMake(0, 32);
// Add a detail disclosure button to the callout.
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
pinView.rightCalloutAccessoryView = rightButton;
NSLog(@"JSON: %@", islandArray); // print
//to display a island image in callout view
UIImageView *calloutImage = [[UIImageView alloc] init];
NSLog(@"%@",[NSURL URLWithString:[[NSUserDefaults standardUserDefaults]objectForKey:@"mapImage"]]);
calloutImage.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[[NSUserDefaults standardUserDefaults]objectForKey:@"mapImage"]]]];
calloutImage.frame = CGRectMake(10, 0, 30, 30);
[calloutImage.layer setCornerRadius:05.0f];
pinView.leftCalloutAccessoryView = calloutImage;
pinView.tintColor = MKPinAnnotationColorRed;
}
else
{
pinView.annotation = annotation;
}
return pinView;
}
return nil;
}
asked 35 secs ago
How to change the callout left accessory image view dynamically based on json response
Aucun commentaire:
Enregistrer un commentaire