2

I'm using a simple marker cluster taken from here https://github.com/ribl/FBAnnotationClusteringSwift

and I see this part of code responsible for putting on the map either a cluster or a pin:

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

It works fine, I see the clusters or single pins, but now I want to add a popup for every pin that user presses, something like presented here:

enter image description here

I found this screenshot here http://www.raywenderlich.com/90971/introduction-mapkit-swift-tutorial and following this tutorial I created a class SingleRequest and also modified the mentioned above code, so now it looks like this:

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
        }


    }

But still, there is nothing visible when I click the pin on the map. What is more, the single pins are now red (default color), so seems like this line:

pinView!.pinColor = .Green

is ignored in the code, probably the rest too.

What am I missing here?

user3766930
  • 5,629
  • 10
  • 51
  • 104

1 Answers1

0

I had exactly the same trouble for 2 days. I have no idea if it's for the same reason (but not enough reputation to comment). (And yes I'm a bit late, sorry ^^)

Do you have this line in your viewDidLoad() function, in your viewcontroller:

mapView.delegate = self 

Also, concerning your color, the line you use is deprecated. Try this :

pinView?.pinTintColor = UIColor.purpleColor()

Hope it helps.