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

标签 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
    }

    }

最佳答案

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

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

关于swift - 如何从 Parse 检索文件以显示在 PFQueryTableVIewController 上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33455311/

相关文章:

ios - 如何从 Parse 导入我的数据?我想从类以外的用户类导入数据

swift - 如何在 xcode 中为每个属性只存储一个值

swift - UIScrollView 滚动时 UISlider 暂停

安卓代码混淆。我想隐藏 Parse.com 的 key

ios - 解析单个字符串字段的查询,其中值与数组中提供的任何字符串匹配

ios - 重新加载数据后,UITableView 中的图片随机移动

ios - 无法使用 SWRevealViewController 和 TabBarController Swift 打开侧边栏

swift - 如何使 Swift 的 String 类型符合 CVarArgType 协议(protocol)?

java - 异常: "No default Constructor provided" exception subclassing ParseObject

ios - 我不能用字符串类型的参数列表调用?