【问题标题】:How to retrieve File from Parse to display on PFQueryTableVIewController?如何从 Parse 中检索文件以显示在 PFQueryTableVIewController 上?
【发布时间】:2015-10-31 18:49:39
【问题描述】:

我正在尝试从 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
    }

    }

【问题讨论】:

  • 出了什么问题?您是否调试并检查了userImage 是否存在?
  • 我在 'cell.userImage.file= pic' 得到一个错误,说 UIImageView 的值没有成员 'file'
  • UIImageView 没有实现file。您可能期望您的单元格的图像视图是PFImageView,它隐藏了获取文件内容、将这些内容解释为图像并将其 imageView(可能是它的超类)图像设置为结果的工作。跨度>

标签: swift parse-platform pfquery


【解决方案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) 
}

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

【讨论】:

  • 好的,所以我现在在使用该代码时不会遇到错误,但是,在 Parse 中,当我发布某些内容时,我看不到班级中用户的图像。这是一个单独的问题吗?
【解决方案2】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多