2017-12-20 7 views
0

私は、単純なマップビューを持っている。そして、MKMapViewのclusterAnnotationForMemberAnnotationsが呼び出されないのはなぜですか?

@IBOutlet private var mapView: MKMapView! 

一つ一つ私が注釈を追加:

mapView.addAnnotation(Annotation(user: user)) 

し、それらのすべてを示しています

mapView.showAnnotations(mapView.annotations, animated: true) 

私もこの方法実装:

func mapView(_ mapView: MKMapView, clusterAnnotationForMemberAnnotations memberAnnotations: [MKAnnotation]) -> MKClusterAnnotation { 
    print(memberAnnotations) 
    return MKClusterAnnotation(memberAnnotations: memberAnnotations) 
} 

しかし、これはまったく呼び出されません。どうして?

enter image description here enter image description here

+0

iOS 11.2シミュレータでも同じことが分かりました。含まれているクラスがデリゲートだと宣言しましたが、単に動作していないようです。 – edwardmp

答えて

3

clusteringIdentifier Fを設定する必要があるかのようにそれが表示されますまたはMKAnnotationView。ピーターの答えは私のために働いた

func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? { 
    let annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: MKMapViewDefaultAnnotationViewReuseIdentifier, for: annotation) 
    annotationView.clusteringIdentifier = "identifier" 
    return annotationView 
} 
0

@、私はそれがより直感的にそれを設定するためのデリゲートメソッドを使用するのではなく、あなたのMKAnnotationViewに直接clusterIdentifierを設定するために見つけるたとえば:これは私のために働いています。

class VehicleAnnotationView: MKAnnotationView { 
    override var annotation: MKAnnotation? { 
     willSet { 
      clusteringIdentifier = "1" 

      canShowCallout = true 
      calloutOffset = CGPoint(x: -5, y: 5) 
      rightCalloutAccessoryView = UIButton(type: .detailDisclosure) 

      image = UIImage(named: "MapVehiclePin") 

     } 
    } 
} 
関連する問題