2

I am setting the title for two MKAnnotationView using the following code:

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

if(([annotation isKindOfClass:[Test_flag class]])) 
{

    MKAnnotationView *pinView = nil; 

    if(annotation != mapView.userLocation) 
    {
        static NSString *defaultPinID = @"PinId1";
        pinView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
        if ( pinView == nil ) pinView = [[[MKAnnotationView alloc]
                                          initWithAnnotation:annotation reuseIdentifier:@"pin1"] autorelease];
        pinView.canShowCallout = YES;
        pinView.animatesDrop = YES;
        [pinView setImage:[UIImage imageNamed:@"flg.png"]];
        [pinView setSelected:YES animated:YES];

    } 
    else 
    {
        [mapView.userLocation setTitle:@"I am here"];
    }
    return pinView;
}
else if(([annotation isKindOfClass:[Distance1 class]])) 
{
    MKAnnotationView *pinView = nil; 

    if(annotation != mapView.userLocation) 
    {
        static NSString *defaultPinID = @"PinId4";
        pinView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
        if ( pinView == nil ) pinView = [[[MKAnnotationView alloc]
                                          initWithAnnotation:annotation reuseIdentifier:@"pin4"] autorelease];

        pinView.canShowCallout = YES;
        [pinView setImage:[UIImage imageNamed:@"Circle_Grey.png"]];
        [pinView setSelected:YES animated:YES];

    } 
    else 
    {
        [mapView.userLocation setTitle:@"I am here"];
    }
    return pinView;
}

When I touch the map, both MKAnnotationView are pointed but they do not show the title. What is the reason? Please help me to find.

Arnaud
  • 7,259
  • 10
  • 50
  • 71
Madhumitha
  • 3,794
  • 8
  • 30
  • 45
  • follow the SO answer http://stackoverflow.com/questions/5589181/displaying-pin-with-title-annotation-once-map-loads – Deepesh Aug 23 '12 at 08:10

1 Answers1

0

You missed to write title method in Test_flag class.

Apurv
  • 17,116
  • 8
  • 51
  • 67
  • I have added NSString *title and @property,@synthesize also in Test_flag class – Madhumitha Aug 23 '12 at 08:08
  • When you are adding annotation to the map, set the value to title. For now hardcode return temp value to check. – Apurv Aug 23 '12 at 08:11
  • that also I did like test_flag.title = @"Distance"; test_flag.subtitle = @"0.0"; – Madhumitha Aug 23 '12 at 08:15
  • Display the code from where you are adding annotations to the map. – Apurv Aug 23 '12 at 08:16
  • Test_flag *test_flag = [[Test_flag alloc] init]; test_flag.title = @"Distance"; test_flag.subtitle = @"0.0"; [mapView addAnnotation:test_flag]; after that am setting the coordinate like test_flag.coordinate = CLLocationCoordinate2DMake(28.458586, 77.109126); – Madhumitha Aug 23 '12 at 08:27