I have an app in wich I have news, which users are added and I want in a table view to show user photo which are taken from DB "_User" and I fetch data from class "news". My code is:
var user = PFUser.current()
let useravatar = user!["profilePicture"] as? PFFile
useravatar?.getDataInBackground{ (imageData, error)in
if imageData != nil {
let image = UIImage(data: imageData!)
cell.userPhoto.image = image
}
}
But this code loads only the current user photo, but I need the user photo for each row, how I can do this? Example:
As you see in pictures I have two user, but it loads only my profile photo.
Load images asynchronously
var user = PFUser.current() //you'e setting an image for same user
let useravatar = user!["profilePicture"] as? PFFile
useravatar?.getDataInBackground{ (imageData, error)in
DispatchQueue.main.async {
if imageData != nil, error == nil {
let image = UIImage(data: imageData!)
cell.userPhoto.image = image
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.