タイトルはJSQMessagesViewControllerを使用して私に提案します。自分のアバター[UIImage]をFirebaseDatabaseのURLから取得し、それを使って解凍するように各ユーザーが気に入っている。 SDWebImage。私はこれを内部に入れることができます。SDWebImageを使用したJSQMessagesViewControllerのユーザー固有のアバター
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = super.collectionView(collectionView, cellForItemAt: indexPath) as! JSQMessagesCollectionViewCell
let message = messages[indexPath.item]
if let messageID = message.senderId {
rootRef.child("users").child(messageID).observe(.value, with: { (snapshot) in
if let profileURL = (snapshot.value as AnyObject!)!["profileURL"] as! String! {
let profileNSURL: NSURL = NSURL(string: profileURL)!
cell.avatarImageView.sd_setImage(with: profileNSURL as URL)
}
})
}
return cell
}
しかし、あなたがメッセージを送信するたびに、テーブルにはイメージが、私はそれが再びすべてのインデックスのパスを通過していると仮定しているとして再表示され、その後消えリロードされます。
アバターのデータソースを処理する方法は以下のとおりです。
override func collectionView(_ collectionView: JSQMessagesCollectionView!, avatarImageDataForItemAt indexPath: IndexPath!) -> JSQMessageAvatarImageDataSource! {
return ???????????????????????????????????????
}
でも、cellForItemAtと同じ論理を構成するようですか?助けてもらえますか?...多くのありがとう。
UPDATE: - ******************************************* ***********************
override func collectionView(_ collectionView: JSQMessagesCollectionView!, avatarImageDataForItemAt indexPath: IndexPath!) -> JSQMessageAvatarImageDataSource! {
let placeHolderImage = UIImage(named: "Circled User Male Filled-25")
let avatarImage = JSQMessagesAvatarImage(avatarImage: nil, highlightedImage: nil, placeholderImage: placeHolderImage)
let message = messages[indexPath.item]
if let messageID = message.senderId {
rootRef.child("users").child(messageID).observe(.value, with: { (snapshot) in
if let profileURL = (snapshot.value as AnyObject!)!["profileURL"] as! String! {
let profileNSURL: NSURL = NSURL(string: profileURL)!
// download avatar image here somehow!?
let manager: SDWebImageManager = SDWebImageManager.shared()
manager.downloadImage(with: profileNSURL as URL!, options: [], progress: { (receivedSize: Int, actualSize: Int) in
print(receivedSize, actualSize)
}, completed: { (image, error, cached, finished, url) in
avatarImage!.avatarImage = image
})
}
})
}
return avatarImage
}
これとは画像サイズをプリントアウトしてエラーなし。画像はプレースホルダ画像から変化していません!...