【发布时间】:2015-04-25 02:29:22
【问题描述】:
这是我当前的查询设置,用于从解析中检索数据并将其设置到 mapView 上的注释引脚。我也想花时间创建并添加一个简单的5:00PM,例如在注释中。有没有办法通过我的查询解析时间而不是日期并将其设置为MKAnnotation?
override func viewDidAppear(animated: Bool) {
var annotationQuery = PFQuery(className: "Post")
currentLoc = PFGeoPoint(location: MapViewLocationManager.location)
//annotationQuery.whereKey("Location", nearGeoPoint: currentLoc, withinMiles: 10)
annotationQuery.whereKeyExists("Location")
annotationQuery.findObjectsInBackgroundWithBlock {
(points, error) -> Void in
if error == nil {
// The find succeeded.
println("Successful query for annotations")
// Do something with the found objects
let myPosts = points as! [PFObject]
for post in myPosts {
let point = post["Location"] as! PFGeoPoint
let annotation = MKPointAnnotation()
annotation.coordinate = CLLocationCoordinate2DMake(point.latitude, point.longitude)
annotation.title = post["title"] as! String!
annotation.subtitle = post["username"] as! String!
self.mapView.addAnnotation(annotation)
}
} else {
// Log details of the failure
println("Error: \(error)")
}
}
这是我的 Parse 后端的照片,可以让您更好地了解:
【问题讨论】:
-
您需要检索“createadAt”字段并使用 NSDateFormatter 对其进行格式化。
-
谢谢泰迪!我会尝试解决它,如果它成功了,我会告诉你。
-
当我检索“createdAt”时,是否将其存储为字符串?
-
不,不。只需使用这个:让 createdAt = post.createdAt。 CreatedAt 不是“真实字段”,而是对象本身的属性。它返回一个 NSDate。
标签: ios xcode swift time parse-platform