【问题标题】:MKPointAnnotation no longer displays title in iOS 11MKPointAnnotation 不再在 iOS 11 中显示标题
【发布时间】:2017-09-25 22:24:57
【问题描述】:

我在 iOS 10 中用于显示注释和标题的代码,在 iOS 11 中不再显示标题。在 iOS 11 中,注释被选中,但标题不再显示。有什么技巧可以让标题像在 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];

【问题讨论】:

    标签: ios objective-c cocoa-touch mkmapview ios11


    【解决方案1】:

    你应该实现这个委托方法:

    - (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 上的结果

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多