我正在处理一个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