我做了一個表視圖控制器的查詢對象的雲,代碼順利,但問題是,當視圖加載分析查詢不顯示在表上。表分析查詢不出現
我嘗試了一些解決方案,但大多數解決方案都是針對USER類的,不適用於任何其他自定義類。
@IBOutlet weak var cloudsTable: UITableView!
var clouds: [PFObject] = [PFObject]()
func loadClouds() {
let cloudsQuery = PFQuery(className: "_Clouds")
cloudsQuery.order(byAscending: "createdAt")
cloudsQuery.findObjectsInBackground(block: { (result, error) in
if error == nil
{
self.clouds = result!
self.cloudsTable.reloadData()
print(self.clouds)
}
})
}
此功能是調用雲類檢索值查看
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return clouds.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cloudsCell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
let userObject:PFObject = clouds[indexPath.row]
cloudsCell.textLabel?.text = userObject.object(forKey: "user") as? String
return cloudsCell
}
這傳遞解析查詢表函數。
有:'cloudsTable.delegate'&'cloudsTable.datasource'設置?你應該在主線程中調用'reloadData()'。 – Larme
@Larme不,我沒有設置它們,你的意思是我必須在子類上設置cloudsTable.delegate和cloudsTable.datasource?或在視圖上加載功能? – user2508528
如果你使用Storyboard,你可以在那裏做。 – Larme