2017-09-25 60 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; 
} 

结果