检索每个用户的个人资料图片解析iOS swift [英] Retrieve profile picture of each user parse iOS swift
本文介绍了检索每个用户的个人资料图片解析iOS swift的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的iOS应用中。有像饲料的推特。每个Feed都有用户名,个人资料图片和他添加的推文。
In my iOS app. there is twitter like feed. and each feed has username, profile picture and the tweets he has added.
并且我能够检索每个Feed的用户名但无法检索个人资料图片。这是我的代码
and im able to retrieve username to each feed but cannot retrieve the profile image. here is my code
let spread:PFObject = self.LiveFeedData.objectAtIndex(indexPath.row) as! PFObject
var user = spread.objectForKey("spreader") as! PFUser
user.fetchIfNeededInBackgroundWithBlock { (obj: PFObject?, error: NSError?) -> Void in
if obj != nil {
var fetchedUser = obj as! PFUser
var username = fetchedUser["username"] as! String
cell.username.text = user.username // This Works FINE
}
}
if let userImageFile = user["photo"] as? PFFile{
userImageFile.getDataInBackgroundWithBlock {
(imageData: NSData?, error: NSError?) -> Void in
if (error != nil) {
if imageData != nil{
cell.profileImage.image = UIImage(data:imageData!)
}else{
println("No Data")
}
}else{
println(error)
}
}
}
推荐答案
如上所述,使用PFImageView可以帮助简化您需要移动到fetch闭包中的代码。
As discussed, using a PFImageView may help streamline the code that you need to move into your fetch closure.
user.fetchIfNeededInBackgroundWithBlock { (obj: PFObject?, error: NSError?) -> Void in
if obj != nil {
var fetchedUser = obj as! PFUser
var username = fetchedUser["username"] as! String
cell.username.text = username
cell.profileImage.file = fetchedUser["photo"] as! PFFile
cell.profileImage.fetchInBackground()
}
}
这篇关于检索每个用户的个人资料图片解析iOS swift的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文