如何自定义多个注解? Parse-Swift
How to customize multiple annotations? Parse-Swift
我已经为此苦苦挣扎了好几天,但我仍然找不到解决方法。基本上我有这个地图视图,我从 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"?
您需要使用类似于 this answer 的 viewForAnnotation
委托方法。确保您还实现了 MKMapViewDelegate 协议并将您的控制器设置为委托。
除此之外,您需要做的就是像现在一样更新您的查询以创建和添加您的自定义注释。
干杯,
罗素
我已经为此苦苦挣扎了好几天,但我仍然找不到解决方法。基本上我有这个地图视图,我从 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"?
您需要使用类似于 this answer 的 viewForAnnotation
委托方法。确保您还实现了 MKMapViewDelegate 协议并将您的控制器设置为委托。
除此之外,您需要做的就是像现在一样更新您的查询以创建和添加您的自定义注释。
干杯, 罗素