我不明白这是怎么回事。我在 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/