2017-09-25 6 views
0

Le code que j'ai utilisé dans iOS 10 pour afficher une annotation et un titre, n'affiche plus le titre dans iOS 11. Dans iOS 11, l'annotation est sélectionnée, mais le titre ne s'affiche plus . Des astuces pour afficher le titre comme dans iOS 10?MKPointAnnotation n'affiche plus le titre dans iOS 11

MKPointAnnotation* theAnnotation = [MKPointAnnotation new]; 
theAnnotation.coordinate = CLLocationCoordinate2DMake(aLocation.latDegrees, aLocation.lonDegrees); 
[theAnnotation setTitle:@"Hello world"]; 

[self.mapView removeAnnotations:self.mapView.annotations]; 
[self.mapView addAnnotation:theAnnotation]; 
[self.mapView showAnnotations:@[theAnnotation] animated:NO]; 
[self.mapView selectAnnotation:theAnnotation animated:YES]; 

Répondre

1

Vous devez mettre en œuvre cette méthode déléguée:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation 
{ 
    static NSString* Identifier = @"PinAnnotationIdentifier"; 
    MKPinAnnotationView* pinView; 
    pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:Identifier]; 

    if (pinView == nil) { 
     pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation 
                reuseIdentifier:Identifier]; 
     pinView.canShowCallout = YES; 
     return pinView; 
    } 
    pinView.annotation = annotation; 
    return pinView; 
} 

Résultat sur iOS 11

enter image description here