2017-09-25 35 views
0

我在iOS 10中用於顯示註釋和標題的代碼不再顯示iOS 11中的標題。在iOS 11中,註釋被選中,但標題不再顯示。任何有關如何在iOS 10中顯示標題的提示?MKPointAnnotation不再顯示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]; 

回答

1

您應該實現此委託方法:在iOS上11

enter image description here

- (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; 
} 

結果