Data is not coming to Annotation method in ios

97 Views Asked by At

How to send the data to

 -(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:
    (id <MKAnnotation>)annotation {

method. Once please observe my code and give me the solution.

-(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation: (id <MKAnnotation>)annotation {
    static NSString *defaultPinID = @"com.invasivecode.pin";

    MKAnnotationView *pinView =(MKAnnotationView *)[mapview dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
    NSLog(@"pinData....%@",pinView);
    if (pinView == nil){
        pinView = [[MKAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:defaultPinID];

        pinView.canShowCallout = YES;
        pinView.enabled = YES;

        pinView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        [pinView setSelected:YES animated:YES];

        pinView.image = [UIImage imageNamed:@"location.png"];
    }
    else{

    }

    return  pinView;
}
1

There are 1 best solutions below

0
On

If you add an annotation to your map and set the class that contains the code you showed above as the map's delegate, then iOS will call viewForAnnotation when ever it needs to redraw it