iOS MapKit MKPointAnnotation 添加披露按钮 - 不显示精确点

iOS MapKit MKPointAnnotation add Disclosure Button - Not showing pinpoints

viewload 我正在循环一些数据并添加点:

    for (id venue in venues) {

        MKPointAnnotation *point = [[MKPointAnnotation alloc] init];
        point.coordinate = coords here;
        point.title = @"title"
        point.subtitle = @"sub";

        [self.map addAnnotation:point];
    }

我想做的是在注释中添加一个简单的披露按钮。我正在使用以下内容:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {

    MKAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:@"String"];
    if(!annotationView) {
        annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"String"];
        annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    }

    annotationView.enabled = YES;
    annotationView.canShowCallout = YES;

    return annotationView;
}

但是在加载视图后,精确定位点不再显示。如果我删除 viewForAnnotation 一切都会正确加载,但是我当然没有披露按钮。

我做错了什么?

如果要将 "PIN" 添加到 MapView,您应该使用 MKPinAnnotationView,而不是 MKAnnotationView

- (MKAnnotationView *)mapView:(MKMapView*)mapView
        viewForAnnotation:(id <MKAnnotation>)annotation
{
  MKPinAnnotationView *annotationView = (MKPinAnnotaionView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"String"];
  if(!annotationView) {
    annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"String"];
    annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
  }
}

正在显示披露按钮。