查询解析,如何在Swift中打印tableView单元格中的数据?
大家好,我正在打印我在Parse中创建的查询,在这里 这工作很好,做我需要它查询解析,如何在Swift中打印tableView单元格中的数据?,swift,uitableview,parse-platform,Swift,Uitableview,Parse Platform,大家好,我正在打印我在Parse中创建的查询,在这里 这工作很好,做我需要它 //store my currentLocations here var locations : [PFObject] = [] PFGeoPoint.geoPointForCurrentLocationInBackground { (geoPoint: PFGeoPoint?, error: NSError?) -> Void in if geoPoint != nil {
//store my currentLocations here
var locations : [PFObject] = []
PFGeoPoint.geoPointForCurrentLocationInBackground { (geoPoint:
PFGeoPoint?, error: NSError?) -> Void in
if geoPoint != nil {
var geoPointLon = geoPoint?.longitude
var geoPonitLan = geoPoint?.latitude
var currentLocation = PFGeoPoint(latitude: geoPonitLan!, longitude: geoPointLon!)
var query = PFQuery(className: "User")
query.whereKey("currentLocation", nearGeoPoint: currentLocation, withinKilometers: 5.0)
query.findObjectsInBackgroundWithBlock({ (objects: [AnyObject]?, error: NSError?) -> Void in
if let myObject = objects as? [PFObject] {
for objects in myObject {
self.locations.append(objects)
}
}
self.tableView.reloadData()
})
}
}
这是我的tableview单元格和行数
func tableView(tableView: UITableView, numberOfRowsInSection section:
Int) -> Int {
return self.locations.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = UITableViewCell()
cell.textLabel?.text = "test"
return cell
}
运行我的应用程序时,“test”会打印正确数量的条目,以便我知道我的查询正在运行
我的问题是,如何在Parse中打印类“User”中名为“currentLocation”的列的实际位置
如果您需要任何其他信息,请告诉我,谢谢假定您的“currentLocation”列是一个字符串,您就可以这样取回它
如果它不是字符串,则可能需要转换它
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = UITableViewCell()
cell.textLabel?.text = self.locations["currentLocation"]
return cell
}
您创建的单元格不正确。嘿,是的,我知道,这是一个用于打印查询数的测试单元格,需要正确的版本来显示数据库中试图通过as转换的内容吗?字符串,但得到一个错误,这列是一个对象,包含地质点位置,有什么想法吗?