0

我试图通过 Parse 为 tableview 拉取用户附近的位置,除了我只得到一个白屏或一个空表。

编辑:在提交地理点附近的查询之前,我忽略了添加位置调用。在测试中,我发现该位置是在“geoPontForCurrentLocationInBackground”下确定的。但是,一旦建立了地理点并提交了查询,用户位置就不会在查询中返回纬度或经度。此外,查询不返回任何对象,我不知道为什么:

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
 }
4

2 回答 2

0

我认为问题在于 Parse 将 User 类视为特殊类。如果您将其视为自定义类,则可能难以查询用户类。

正确且经过测试的方法是使用PFUser的查询功能。

var query = PFUser.query()
于 2015-04-01T21:01:15.480 回答
0

您正在设置查询,但从未实际执行它。根据 Parse 文档,您需要添加:

// Final list of objects
queryResults = query.findObjects()

在你的queryForTable() return语句之前为了得到查询对象。

于 2015-04-01T20:50:16.513 回答