我正在使用从这里获取的简单标记集群https://github.com/ribl/FBAnnotationClusteringSwift
我看到这部分代码负责在地图上放置一个集群或一个引脚:
func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! {
var reuseId = ""
if annotation.isKindOfClass(FBAnnotationCluster) {
reuseId = "Cluster"
var clusterView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId)
clusterView = FBAnnotationClusterView(annotation: annotation, reuseIdentifier: reuseId, options: nil)
return clusterView
} else {
reuseId = "Pin"
var pinView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId) as? MKPinAnnotationView
pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
pinView!.pinColor = .Green
return pinView
}
}
它工作正常,我看到集群或单个引脚,但现在我想为用户按下的每个引脚添加一个弹出窗口,如下所示:
我在这里找到了这个截图http://www.raywenderlich.com/90971/introduction-mapkit-swift-tutorial
并按照本教程创建了一个类SingleRequest
并修改了上面提到的代码,所以现在看起来像这样:
func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! {
var reuseId = ""
if annotation.isKindOfClass(FBAnnotationCluster) {
reuseId = "Cluster"
var clusterView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId)
clusterView = FBAnnotationClusterView(annotation: annotation, reuseIdentifier: reuseId, options: nil)
return clusterView
} else {
reuseId = "Pin"
if let annotation = annotation as? SingleRequest {
var pinView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId) as? MKPinAnnotationView
pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
pinView!.pinColor = .Green
pinView!.canShowCallout = true
pinView!.calloutOffset = CGPoint(x: -5, y: 5)
pinView!.rightCalloutAccessoryView = UIButton(type: .DetailDisclosure) as UIView
return pinView
}
return nil
}
}
但是,当我单击地图上的图钉时,仍然没有任何可见的东西。更重要的是,单个引脚现在是红色(默认颜色),所以看起来像这条线:
pinView!.pinColor = .Green
在代码中被忽略,可能其余的也被忽略。
我在这里想念什么?