【问题标题】:PFQueryTableViewController not loading from Parse into Swift tableViewPFQueryTableViewController 未从 Parse 加载到 Swift tableView
【发布时间】:2015-05-21 02:05:19
【问题描述】:

我是 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
}

【问题讨论】:

    标签: ios swift parse-platform pfquery pfquerytableviewcontrolle


    【解决方案1】:

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

    从 Parse 文档中,查询用户有一种特殊的方法:

    示例:

    var query = PFUser.query()

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

    var girls = query.findObjects()

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

    希望对你有帮助

    【讨论】:

    • 我不知道我脑海中的语法但是,尝试使用var user = PFUser.currentUser()首先检查当前用户是否存在。然后,如果它通过了,那么你就查询用户,或者显示错误。
    • 如果用户存在,并且查询成功,然后尝试通过调用 self.reloadData() 在 vi​​ewDidLoad 方法中重新加载 tableview 还要确保在实用程序选项卡中身份检查器下的情节提要中,您的自定义类名称是连接到 MasterTableViewController,因为那是数据的来源。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多