我正在處理一個Parse查詢,該查詢抽取基於地理位置的名稱和照片,然後將它們加載到表視圖上。查詢的第一部分即將通過,沒有問題。我被困在拉/加載照片的第二部分。PFFile不加載到表視圖
我可能會因爲在queryForTable方法中缺少對圖像的調用而出錯。在這裏我已經嘗試了includeKey(失敗了,因爲它不是指向另一個對象的指針);我還使用getDataInBackgroundWithBlock來調用圖像。在每種情況下,我會嘗試加載查詢的對象到像cell.imageData.image = photo這樣的線視圖上。
但是不同的SO賬戶也表明這個調用可以在tableView方法中進行,這就是我在下面的內容。我梳理了SO,Parse.com和其他資源,但我還沒有遇到過解決方案。希望有人能幫助:
override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!, object: PFObject?) -> Stores! {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! Stores
if let object = object {
let Name = object.valueForKey("Name") as? String
cell.storeList.text = Name
let photo = object.objectForKey("Photos") as? PFFile
photo?.getDataInBackgroundWithBlock {(imageData: NSData!, error: NSError!) -> Void in
if error == nil {
let image = UIImage(data: imageData)
cell.storeImage.file = photo
}
}}
return cell as Store
將背景塊作爲單元格dequeu運行是一個壞主意。 – ericgu
您可以使用我的黑客: http://stackoverflow.com/questions/28649257/parse-pfquerytableviewcontroller-pfquerytableviewcell-subclass-breaks-pfimag – ericgu
謝謝,埃裏克!我試圖實施黑客攻擊,但圖像也沒有出現。我已經刪除了「getDataInBackgroundWithBlock」。 – Christine