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