解析查询没有任何回报

问题描述:

我试图通过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 
} 

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

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

var query = PFUser.query() 
+1

谢谢Eric。我尝试用空参数省略类名,但它也没有返回任何对象。 – Christine 2015-04-01 21:40:33

+0

那不是我提供的。 – ericgu 2015-04-01 21:43:55

+0

尝试使用PFUser的查询功能而不是PFQuery – ericgu 2015-04-01 21:44:46

您正在设置查询,但从未实际执行它。 Per the Parse documents,您需要添加:

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

queryForTable()return声明之前,为了得到的查询对象。

+0

谢谢,亚当。我只是用'query.findObjects'来测试它,但它仍然没有加载任何对象。我建议在方法建立后添加'var queryResults = NSString()'作为第一行,然后按照建议添加'queryResults = query.findObjects()'。还用'query.findObjects()'运行它。 (我应该补充一点,我是Swift和Parse的新手;请原谅我的无知。) – Christine 2015-04-01 21:34:46

+0

您需要合并@ ericgu对自定义User类的建议,并确保您返回'queryResults'变量。 – 2015-04-02 01:12:17

+0

谢谢亚当! (太糟糕了,我不能检查这两个答案,因为它是组合,如果可以的话,我会加快回复。) – Christine 2015-04-02 03:57:40