1

I have been struggling with this for days but I still can't find a way to do it. Basically I have this map view and I am getting the annotations data (location,title,subtitle) from Parse, all I want to do is to replace the default pins with a custom one, I managed to customize one when I only use one annotation but for multiple it is not working, this is what I have for adding the annotations:

      func setAnnotations(){

    //Run query and get objects from parse, then add annotations
    var query = PFQuery(className: "Countries")
    query.orderByDescending("Location")
    query.findObjectsInBackgroundWithBlock{

        (objects:[AnyObject]?,error: NSError?)-> Void in

        if error == nil{

            let myObjects = objects as! [PFObject]
            for object in myObjects{

                 //data for annotation
                 var annotation = MKPointAnnotation()
                 let place = object["Location"] as? PFGeoPoint
                 let placeName = object["nameEnglish"] as? String
                 annotation.title = placeName
                 annotation.subtitle = placeName
                 annotation.coordinate = CLLocationCoordinate2DMake(place!.latitude,place!.longitude)

                 //add annotations
                 self.mapView.addAnnotation(annotation)
                }

        }else{println(error)}
    }
}

How would I apply the "dequeueReusableAnnotationViewWithIdentifier" here?

rici
  • 234,347
  • 28
  • 237
  • 341
Noah-1
  • 396
  • 1
  • 5
  • 20
  • All of the parse-related fetching seems alright, so my guess is that the error is related with how you're trying to display the annotations. Could you elaborate more about what you mean by replace the default pins with a custom one? You appear to be using the default one in your example. – Russell Sep 01 '15 at 20:37
  • Yeah, I am trying to replace the current ones with a custom Image I have, that is only the code for displaying multiple annotations that I get from parse, so my question is how would I apply "dequeueReusableAnnotationViewWithIdentifier" to add the custom ones in this specific case. – Noah-1 Sep 01 '15 at 21:19

1 Answers1

1

You will want to use the viewForAnnotation delegate method similar to this answer. Make sure you also implement the MKMapViewDelegate protocol and set your controller to be the delegate.

Other than that, all you need to do is update your query to create and add your custom annotations like you are right now.

Cheers, Russell

Russell
  • 3,099
  • 2
  • 14
  • 18