2016-08-04 80 views
0

我正在使用cocoapod FBAnnotationClusteringSwift,並且可以將我的註釋組合在一起。但是,我想循環所有那些在點擊集羣註釋時聚集在一起的註釋。我想遍歷我的羣集註釋中的所有註釋

我該怎麼做?

func mapView(mapView: MKMapView, didSelectAnnotationView view: MKAnnotationView) { 
    if (view.annotation!.isKindOfClass(FBAnnotationCluster) == true){ 

     //I WANT TO LOOP OVER ALL ANNOTATIONS IN THE CLUSTER HERE 

    } 
    if (view.annotation!.isKindOfClass(ItemAnnotation) == true){ 
     let annotation = view.annotation! as? ItemAnnotation 
     if let annotation = annotation, let item = annotation.item, d = delegate{ 
      d.itemAnnotationPressed(item) 
     } 
    } 
} 
+0

可以得到所有所述方法mapView.annotations註釋它返回當前註釋的陣列中的地圖 –

回答

0
func mapView(mapView: MKMapView, didSelectAnnotationView view: MKAnnotationView) { 
     if (view.annotation!.isKindOfClass(FBAnnotationCluster) == true){ 
      let annotation = view.annotation! as? FBAnnotationCluster 

      var itemListFromAnnotation = [Item]() 

      for annotation in (annotation?.annotations)! { 
       let itemAnnotation = annotation as? ItemAnnotation 
       itemListFromAnnotation.append((itemAnnotation?.item)!) 
      } 

      if let d = delegate{ 
       d.itemClusterAnnotationPressed(itemListFromAnnotation) 
      } 
     } 
     if (view.annotation!.isKindOfClass(ItemAnnotation) == true){ 

      mapView.deselectAnnotation(view.annotation, animated: false) 

      let annotation = view.annotation! as? ItemAnnotation 
      if let annotation = annotation, let item = annotation.item, d = delegate{ 
       d.itemAnnotationPressed(item) 
      } 
     } 
    }