簡體   English   中英

iOS如何使用Parse Swift獲取每個用戶的個人資料圖像

[英]IOS How to fetch profile image for each user use Parse Swift

我有一個新聞應用程序,它添加了用戶,並且希望在表格視圖中顯示從數據庫“ _User”拍攝的用戶照片,並從類“ news”中獲取數據。 我的代碼是:

 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

        }
    }

但是此代碼僅加載當前的用戶照片,但是我需要每一行的用戶照片,我該怎么做? 例:

--

如您在圖片中看到的,我有兩個用戶,但僅加載我的個人資料照片。

異步加載圖像

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

      }
   }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM