Parse 查询没有 returns
No returns for Parse query
我正在尝试通过 Parse 提取用户附近的位置以供 table 查看,但我只得到一个白屏或空白 table。
已编辑: 在提交地理点附近的查询之前,我忽略了添加对位置的调用。在测试中,我发现位置是在'geoPontForCurrentLocationInBackground'下确定的。但是,在建立地理点并提交查询后,用户位置 return 在查询中没有纬度或经度。此外,查询没有 return 任何对象,我不确定为什么:
override func queryForTable() -> PFQuery! {
var query = PFQuery(className: "User")
PFGeoPoint.geoPointForCurrentLocationInBackground {
(userLocation: PFGeoPoint!, error: NSError!) -> Void in
if error == nil {
}
}
let point: PFGeoPoint = PFGeoPoint(latitude: self.userLoc.latitude, longitude: self.userLoc.longitude)
query.whereKey("location", nearGeoPoint: point, withinMiles: 50.0)
query.limit = 10
return query
}
override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!, object: PFObject!) -> PFTableViewCell! {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as Shops
if let object = object {
if let shopName = object.valueForKey("shopName") as? String {
cell.shopList.text = shopName
}
}
return cell as Shops
}
您正在设置查询,但从未实际执行过。 Per the Parse documents,您需要添加:
// Final list of objects
queryResults = query.findObjects()
在您的 queryForTable()
return
语句之前以获取查询对象。
我认为问题在于 Parse 将用户 class 视为 特殊 class。如果您将用户 class 视为自定义 Class,您可能难以查询它。
正确且经过测试的方法是使用 PFUser 的查询函数。
var query = PFUser.query()
我正在尝试通过 Parse 提取用户附近的位置以供 table 查看,但我只得到一个白屏或空白 table。
已编辑: 在提交地理点附近的查询之前,我忽略了添加对位置的调用。在测试中,我发现位置是在'geoPontForCurrentLocationInBackground'下确定的。但是,在建立地理点并提交查询后,用户位置 return 在查询中没有纬度或经度。此外,查询没有 return 任何对象,我不确定为什么:
override func queryForTable() -> PFQuery! {
var query = PFQuery(className: "User")
PFGeoPoint.geoPointForCurrentLocationInBackground {
(userLocation: PFGeoPoint!, error: NSError!) -> Void in
if error == nil {
}
}
let point: PFGeoPoint = PFGeoPoint(latitude: self.userLoc.latitude, longitude: self.userLoc.longitude)
query.whereKey("location", nearGeoPoint: point, withinMiles: 50.0)
query.limit = 10
return query
}
override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!, object: PFObject!) -> PFTableViewCell! {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as Shops
if let object = object {
if let shopName = object.valueForKey("shopName") as? String {
cell.shopList.text = shopName
}
}
return cell as Shops
}
您正在设置查询,但从未实际执行过。 Per the Parse documents,您需要添加:
// Final list of objects
queryResults = query.findObjects()
在您的 queryForTable()
return
语句之前以获取查询对象。
我认为问题在于 Parse 将用户 class 视为 特殊 class。如果您将用户 class 视为自定义 Class,您可能难以查询它。
正确且经过测试的方法是使用 PFUser 的查询函数。
var query = PFUser.query()