gpt4 book ai didi

swift - 我想循环遍历集群注释中的所有注释

转载 作者:行者123 更新时间:2023-11-30 13:10:45 24 4
gpt4 key购买 nike

我正在使用 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)
}
}
}

最佳答案

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)
}
}
}

关于swift - 我想循环遍历集群注释中的所有注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38764256/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com