PFFile 未加载到 Table 视图

PFFile Not Loading onto Table View

我正在处理一个 Parse 查询,该查询提取基于地理的名称和照片,然后将它们加载到 table 视图中。查询的第一部分没有问题。我卡在了 pulling/loading 照片的第二部分。

我可能会出错,因为在 queryForTable 方法中缺少对图像的调用。在这里,我尝试了 includeKey(失败了,因为它不是指向另一个对象的指针);我还调用了图像,使用 getDataInBackgroundWithBlock。在每种情况下,我都会尝试使用 cell.imageData.image = photo.

之类的行将查询的对象加载到 table 视图中

但是不同的 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

您应该使用 image 而不是 cell.storeImage.file = photo

所以在你的完成块中,你应该有:

let image = UIImage(data: imageData)
cell.storeImage.file = image

最终对我有用的是将文件 属性 放在调用中:

cell.imageView.loadInBackground {(image: UIImage!, error: NSError!) -> Void in 
  if error == nil {
    cell.imageView.file = object!.objectForKey("Photos") as? PFFile
   }

重新访问 Parse 文档表明它是“.file”,而不是“.image”。此外,对于异步调用,我使用 'loadInBackground' 而不是 'loadInBackgroundWithBlock'。希望这可以帮助那些对同样问题感到困惑的人。

感谢@BHendricks、@ericgu、@danh 分享他们的观点!尝试你所有的建议肯定让我更接近我的答案。