ios - 解析 - imageView 作为 PFFile 不会加载

标签 ios swift parse-platform

我不明白这是怎么回事。我在 Parse 中将图像保存为 PFFile。我能看到它,我知道它就在那里。我想把它作为细胞图像。下面的其余代码工作正常,并且 PFFile 的内存地址也打印出来。 textLabel 和 detailTextLabel 也很好,但图像不会显示(即使我删除“loadInBackground”)。有什么想法吗?

 override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath, object: PFObject?) -> PFTableViewCell? {
    var cell = tableView.dequeueReusableCellWithIdentifier("Cell") as! PFTableViewCell!
    if cell == nil {
     cell = PFTableViewCell(style: .Subtitle, reuseIdentifier: "Cell")
    }

    if let name = object?["name"] as? String {
        cell.textLabel?.text = name
    }

    if let artist = object?["artist"] as? String {
        cell.detailTextLabel?.text = artist
    }

    if let artwork = object?["artwork"] as? PFFile {
        println("we've got an artwork image \(artwork)")
        //cell!.imageView!.image = UIImage(named: "placeholder.jpg")
        cell.imageView?.file = artwork
        cell.imageView?.loadInBackground()
    }

    return cell
}

最佳答案

Parse 只是保存对表中图像的引用,您将必须执行另一个异步调用来检索消息。:

let artwork = object?["artwork"] as PFFile
artwork.getDataInBackgroundWithBlock {
  (imageData: NSData?, error: NSError?) -> Void in
  if error == nil {
    if let imageData = imageData {
        let image = UIImage(data:imageData)
    }
  }
}

关于ios - 解析 - imageView 作为 PFFile 不会加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30835143/

相关文章:

arrays - 在 Swift 中,如何在 PFQueryTableViewController 上执行一个查询先于另一个查询?

javascript - 发送指定 URL 的静态文件

ios - XCode 6.3 向 tableviewcell 添加边距

ios - 在 AppDelegate 中检测抖动

swift - 在 Swift 中,用参数覆盖 func。将目标添加到项目

ios - 单击单元格中的按钮时如何解析以播放某首歌曲?

ios - react native ios : App crashes when it sent to the background

objective-c - 为什么旋转后 UIImageView 的大小会发生变化?

ios - 在 dismissViewController 上重新加载 View (模态)

ios - React Native Firebase 更新到 5.0.0 ios 错误