Search code examples
iphonemkmapviewmkannotationviewcallouts

Custom callOut for A pin in a mkMapview of iphone!! .... Data miss match for default call out and custom call out


pinView Callout

I am trying for a custom callout for a pin dropped in a mapView .. I am able to do this by hiding the default callout of pinView and showing my custom call out there. ().. everything is working fine ... But only prob is i am not able to assign the correct information for the call out ..I had shown the Default call out in which info is different than my custom call out. I ve attached the scrren shot .....

Here is my code

-(void)mapViewImplementaion
{

    [mapview setMapType:MKMapTypeStandard];
    mapview.showsUserLocation=YES;


    for (int i =0;i<[allResultsArr count];i++)
    {
        List_Map_details *object=[allResultsArr objectAtIndex:i];

        CLLocationCoordinate2D coordinat = {[object.lati floatValue], [object.longi floatValue]};

        [mapview setRegion:MKCoordinateRegionMake(coordinat, 
                                                      MKCoordinateSpanMake(0.027f, 0.027f))];



DisplayMapPark *ann = [[DisplayMapPark alloc] init]; 

        ann.title =[NSString stringWithFormat:@"%@",object.forRetailerName];
        ann.subtitle=[NSString stringWithFormat:@"%@ %@ %@",object.forAddress,object.forZipCode,object.forCityName];
        ann.latitude=[object.lati floatValue];
        ann.longitude=[object.longi floatValue];
        ann.coordinate = coordinat; 
        [mapview addAnnotation:ann];
        [ann release];



}




CalloutMapAnnotationView *calloutMapAnnotationView;

int m=1;


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

    MKAnnotationView *pinView = nil; 



// here i wrote some code for my custom callout to generate(not shown)


if(annotation != mapview.userLocation) 
    {

        //int i=0;
        static NSString *defaultPinID = @"com.invasivecode.pin";
        pinView = (MKAnnotationView *)[mapview dequeueReusableAnnotationViewWithIdentifier:defaultPinID];

if ( pinView == nil ) 
            pinView = [[[MKAnnotationView alloc]
                                          initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];


        NSString *imagName = [NSString stringWithFormat:@"%d.png", m];
        UIImage *image = [UIImage imageNamed:imagName];
        [pinView setImage:image];

        pinView.canShowCallout = NO;
        // To show this in scrren Shot i set it to Yes;


        [pinView setAnnotation:annotation];

        pinView.tag=m;

        UIButton *rightButton=[UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        pinView.rightCalloutAccessoryView=rightButton;
        //pinView.rightCalloutAccessoryView.frame=CGRectMake(0, 0, 60, 60);

        m++;
    } 

    else 
    {
        [mapview.userLocation setTitle:@"Ik ben hier"];


    }

    pinView.annotation = annotation;
    [rightButton release];
    return pinView;

}

Hi if any one is awre of this .. please help !!!!!


Solution

  • I solved this issue. It was the mistake by me. I was just not assigning the tags to the pins properly .. and when the user selects the pin i was reading some other pin's information.... Thanks all