如何从 Parse 中检索文件以显示在 PFQueryTableVIewController 上?

How to retrieve File from Parse to display on PFQueryTableVIewController?

我正在尝试从 Parse 中检索用户个人资料图片(文件)到我的 PFQueryTableViewController。我相信我已经正确地编写了我的代码,但我可能做错了什么。那么如何从解析中检索用户图像以显示在我的查询中?

  override func tableView(tableView: UITableView?, cellForRowAtIndexPath indexPath: NSIndexPath?, object: PFObject!) -> PFTableViewCell? {
   let cell = tableView!.dequeueReusableCellWithIdentifier("TCell", forIndexPath: indexPath!) as! Tweets


if let userTweet : PFObject = self.tweets.objectAtIndex(indexPath!.row) as! PFObject {

cell.username.text = object["account"] as? String
cell.post.text = object["post"] as? String
cell.post.numberOfLines = 0

    if let Pic = object["photo"] as? PFFile {
        cell.userImage.image = UIImage(named: "Image")
        cell.userImage.file = Pic
    }

    }

您没有为其中之一加载 PFFile

if let pic = object["photo"] as? PFFile {
    // Make sure your imageView is a PFImageView
    let imageView = cell.userImage as! PFImageView
    // I assume this is the placeholder image while your load your image files from Parse
    imageView.image = UIImage(named: "image.png")
    imageView.file = pic
    // Load the image file however you see fit
    imageView.loadInBackground(nil) 
}

附带说明一下,最好不要将常量大写,因为它们可能会与代码中的 class 名称混淆。

看起来您的代码使用的是 PFImageView,但单元格子类将其呈现为 UIImageView,因此编译器会报错。您需要确保正确设置图像视图并将其显示为 PFImageView.