【问题标题】:Parse - imageView as PFFile won't loadParse - imageView as PFFile 不会加载
【发布时间】:2015-06-14 22:18:30
【问题描述】:

我不明白发生了什么。我在 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
}

【问题讨论】:

    标签: ios swift parse-platform


    【解决方案1】:

    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)
        }
      }
    }
    

    【讨论】:

    • 我认为您的代码应该可以工作,但仍然不行。解析文档不建议在后台获取图像。实际上,由于我使用的是 PFQueryTableViewController,我应该做的就是将“setImageKey”设置为“artwork”,我已经这样做了,但它仍然没有加载图像。
    • 我从情节提要中删除了原型单元,并且它起作用了。顺便说一句,我不需要在后台获取它。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-10-23
    • 1970-01-01
    • 1970-01-01
    • 2014-08-07
    • 2017-07-07
    • 1970-01-01
    • 2015-08-27
    相关资源
    最近更新 更多