1

I want to show the title of the pin(MKAnnotation)every time when I added the annotation.I added the following code for that.But it is not working.Please help me to find out. I just added the pin like this.

ann = [[DisplayMap alloc] init];
ann.title = @"aaa";
ann.subtitle = @"bbbn";
[mapView addAnnotation:ann];

after that i added the following code in this method

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

    if(annotation != mapView.userLocation) 
    {
        static NSString *defaultPinID = @"com.invasivecode.pin";
        pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
        if ( pinView == nil ) 
            pinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];

        pinView.pinColor = MKPinAnnotationColorRed; 
        pinView.canShowCallout = YES;
        pinView.animatesDrop = YES;
        pinView.selected = YES;
        [mapView selectAnnotation:annotation animated:YES];

        //[pinView setImage:[UIImage imageNamed:@"user.png"]];

    }
}

what mistake I have done?

Atulkumar V. Jain
  • 5,102
  • 9
  • 44
  • 61
Madhumitha
  • 3,794
  • 8
  • 30
  • 45
  • 1
    You mean you want to show the callout immediately when the annotation is added (not "when you touch the map")? You can't set `selected` property directly and you can't call `selectAnnotation` in `viewForAnnotation`. See [this](http://stackoverflow.com/questions/4151094/getting-the-title-to-show-up-when-map-loads-with-mkmap/4151381#4151381), [this](http://stackoverflow.com/questions/7884379/mkannotation-not-getting-selected-in-ios5), and [this](http://stackoverflow.com/questions/8824517/how-can-the-mkuserlocation-be-programmatically-selected). –  Jun 06 '12 at 12:26

0 Answers0