MKPointAnnotation 在 iOS 11 中不再显示标题
MKPointAnnotation no longer displays title in iOS 11
我在iOS10中使用的显示注释和标题的代码,在iOS11中不再显示标题。在iOS11中,注释被选中,但标题不再显示。关于让标题像在 iOS 10 中那样显示的任何提示?
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];
你应该实现这个委托方法:
- (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;
}
结果 iOS 11
我在iOS10中使用的显示注释和标题的代码,在iOS11中不再显示标题。在iOS11中,注释被选中,但标题不再显示。关于让标题像在 iOS 10 中那样显示的任何提示?
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];
你应该实现这个委托方法:
- (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;
}
结果 iOS 11