簡體   English   中英

PFQueryTableViewController無法從Parse加載到Swift tableView中

[英]PFQueryTableViewController not loading from Parse into Swift tableView

我是Swift的新手,我試圖找到當前用戶位置,然后查詢所有附近的用戶,然后將其加載到我的情節UITableView中的UITableView中。 但是,當我構建代碼時, UITableView沒有數據顯示(Parse是我的后端)。 我試圖研究此問題,並找到了使用PFQueryTableViewController這種方式:

PFQueryTableViewController在迅速不加載數據

但是,當我這樣做時

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
}

在您的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

希望有幫助

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM