PFQueryTableViewController没有从Parse加载到Swift tableView中

时间:2015-05-21 02:05:19

标签: ios swift parse-platform pfquery pfquerytableviewcontrolle

我是Swift的新用户,我正在尝试查找当前用户位置,然后查询附近的所有用户,然后将其加载到我的故事板中的UITableView。但是,当我构建我的代码时,我的UITableView中没有数据显示(Parse是我的后端)。我试图研究这个问题并找到了使用PFQueryTableViewController的方法:

PFQueryTableViewController in swift not loading data

但是,当我这样做时

required init(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)
  }

始终返回NSException错误。如何解决该问题或修复以下代码以将我的解析数据返回到我的表视图中?

import UIKit
import Parse
import ParseUI
import CoreLocation

class MasterTableViewController: PFQueryTableViewController {

var usersLocation: PFGeoPoint? {
    didSet {
        // This will reload the tableview when you set the users location.
        // Handy if you want to keep updating it.
        if (tableView != nil) {
            tableView.reloadData()
        }
    }
}

override func viewDidLoad() {
    super.viewDidLoad()

    PFGeoPoint.geoPointForCurrentLocationInBackground { point, error in
        if error == nil {
            self.usersLocation = point
        }
    }

}

override func queryForTable() -> PFQuery {
    var query = PFQuery(className: "User")
    if let location = usersLocation {
        query.whereKey("location", nearGeoPoint: location)
    }
    query.limit = 10
    return query
}

1 个答案:

答案 0 :(得分:0)

在您的queryForTable方法中,您似乎正在尝试查询用户类。

从Parse docs到查询用户,有一种特殊的方式:

示例:

var query = PFUser.query()

query.whereKey("gender", equalTo:"female")

var girls = query.findObjects()

https://www.parse.com/docs/ios/guide#users-querying

希望有帮助

相关问题