我这几天一直在努力,但我仍然无法找到办法。基本上我有这个地图视图,我从Parse获取注释数据(位置,标题,副标题),我想要做的是用自定义的替换默认引脚,我设法在我只使用一个注释时自定义一个但是对于多个它不起作用,这就是我添加注释的内容:
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)}
}
}
我如何应用" dequeueReusableAnnotationViewWithIdentifier"这里吗?
答案 0 :(得分: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