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

时间:2015-10-31 18:49:40

标签: swift parse-platform pfquery

我试图将用户个人资料图片(文件)从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
    }

    }

2 个答案:

答案 0 :(得分:1)

您未加载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) 
}

作为旁注,最好不要将常量大写,因为它们可能会与代码中的类名混淆。

答案 1 :(得分:0)

看起来您的代码使用PFImageView,但是单元子类将它呈现为UIImageView,因此编译器正在抱怨。您需要确保正确设置图像视图并将其公开为PFImageView