【发布时间】:2017-07-24 18:09:00
【问题描述】:
我在尝试将保存为 PFGeoPoints 的多个注释显示到我的地图时遇到问题。当我运行我的查询时,它工作正常,但是它只在地图上显示最近保存的注释,而我需要它来显示迄今为止保存的每个注释。
这是我的代码:
let query = PFQuery(className: "location")
query.findObjectsInBackground { (objects, error) in
if let brandsLocation = objects {
for object in brandsLocation {
if let brandLocation = object as? PFObject {
let annotation = MKPointAnnotation()
let annotationPoint = object["geoPoint"] as! PFGeoPoint
self.annotation.coordinate = CLLocationCoordinate2DMake(annotationPoint.latitude, annotationPoint.longitude)
self.annotation.title = brandLocation["annotationTitle"] as? String
self.annotation.subtitle = brandLocation["annotationSubtitle"] as? String
self.map.addAnnotation(self.annotation)
}
}
}
}
非常感谢任何帮助,我知道这可能是一个小问题,导致并非我的所有注释都被查询。感谢您的帮助!!!!
【问题讨论】:
-
您是否设置了断点以查看您在遍历对象时循环了多少次?
-
不,我没见过我对断点不太熟悉。你能建议把它们放在哪里吗?我会在代码末尾的四个大括号之后思考。
-
不,你会想要一个
if let brandLocation...,看看它点击了多少次。如果它只命中一次,由于某种原因,您只命中了一个对象,这就是为什么您只得到一个注释。如果它多次命中,那么您将需要逐步查看您最终为注释属性设置的值。 -
它肯定不止一次,实际上是我拥有的三个注释的三倍。但是,只有一个仍在显示
-
注解是否有一些特定的东西会导致查询只产生一个注解?
标签: swift dictionary parse-platform annotations