gpt4 book ai didi

ios - 检索每个用户的个人资料图片解析 iOS swift

转载 作者:可可西里 更新时间:2023-11-01 01:05:26 25 4
gpt4 key购买 nike

在我的 iOS 应用中。有推特之类的提要。每个提要都有用户名、头像和他添加的推文。

并且我能够检索每个供稿的用户名,但无法检索个人资料图像。这是我的代码

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)
}
}

}

This iS Tweet Feed

enter image description here

最佳答案

如前所述,使用 PFImageView 可能有助于简化您需要移入 fetch 闭包的代码。

    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 - 检索每个用户的个人资料图片解析 iOS swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31963918/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com