2010-03-20 9 views

Répondre

4

Outil MKMapViewDelegate délégué;

Outil - (MKAnnotationView *) mapView: (MKMapView *) mapView_ viewForAnnotation: (id <MKAnnotation>) annotation_;; par exemple comme ceci:

- (MKAnnotationView *) mapView: (MKMapView *) mapView_ viewForAnnotation: (id <MKAnnotation>) annotation_ { 

    MKPinAnnotationView *pin = (MKPinAnnotationView *) [self.mapView dequeueReusableAnnotationViewWithIdentifier: @"YourPinId"]; 
    if (pin == nil) { 
     pin = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation_ reuseIdentifier: @"YourPinId"] autorelease]; 
    } 
    else { 
     pin.annotation = annotation_; 
    } 
    pin.pinColor = MKPinAnnotationColorRed; 
    [pin setCanShowCallout:YES]; 
    pin.animatesDrop = YES; 
    return pin; 
} 

Afficher la broche après la carte a terminé le chargement:

- (void) dropPin { 
    [mapView addAnnotation:self.annotation]; 
    [mapView selectAnnotation:self.annotation animated:YES];   
} 

- (void) mapViewDidFinishLoadingMap: (MKMapView *) mapView_ { 
    // if done loading, show the call out 
    [self performSelector:@selector(dropPin) withObject:nil afterDelay:0.3]; 
} 

Ce code a une propriété appelée annotation qui implémente MKAnnotation. En outre, il anime la chute de broche aussi, mais il devrait être assez explicite.

HTH.

+0

Merci beaucoup ... très utile! – Mat

3

Alfons répondu à la question, mais si vous cherchez quoi exactement ouvre automatiquement la légende, il est cette partie:

[mapView selectAnnotation:annotation animated:YES]; 
+0

Brillant! Une solution simple, mais exactement ce que je cherchais. Une ligne de code (après avoir créé une nouvelle annotation) pour obtenir l'affichage du titre et du sous-titre. Merci pour ce conseil –