제목이 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
}
이 그 이미지의 크기를 인쇄에 오류가 없습니다. 그러나 이미지는 자리 표시 자 이미지에서 변경되지 않습니다! ...