JSQMessagesViewController로 작업 중이며 버블 컬러 세 개를 구현했습니다. 추가 색상은 검토 된 대화방에서 승인되지 않은 메시지를 나타내도록 설계되었습니다.JSQMessagesViewController 업데이트시 버블 이미지 색상 업데이트
채팅 메시지 항목이 변경되면 Firebase 백엔드를 실행하고 승인 된 플래그를 업데이트하고 있습니다.
모두 잘되고 있으며 실시간으로 데이터가 변경되고 있습니다. 문제는 채팅 버블 색상과 관련이 있습니다. 내가 무엇을 변경하든 상관 없습니다.
레이아웃, reloaddata를 무효화하려고 시도했습니다. 셀에 직접 액세스합니다 (읽기 전용으로 제공됨). 채팅보기를 종료하고 돌아 오는 것 외에는 색을 변경하지 못하는 것 같습니다.
messageRef.observe(.childChanged, with: { (snapshot) in
let key = snapshot.key
if let dict = snapshot.value as? [String: AnyObject] {
let approved = (dict["approved"]?.boolValue ?? true)
let indexOfMesage = self.messages.index(where:{$0.key == key})
var message = self.messages[indexOfMesage!]
message.approved = approved
print(message)
self.collectionView.performBatchUpdates({() -> Void in
self.collectionView.collectionViewLayout.invalidateLayout()
self.collectionView.reloadData()
}, completion:nil)
}
어떤 도움을 주시면 감사하겠습니다. 위의 코드는 많은 시도 중 하나 일뿐입니다.
아래 "응답"후 추가 정보를 요청하는 "messageBubbleImageDataForItemAt"를 추가하십시오.
override func collectionView(_ collectionView: JSQMessagesCollectionView!, messageBubbleImageDataForItemAt indexPath: IndexPath!) -> JSQMessageBubbleImageDataSource! {
let message = messages[indexPath.item] // 1
if message.messageItem.senderId == senderId { // 2
if (message.approved == true){
return outgoingBubbleImageView
}else{
return outgoingUnnaprovedBubbleImageView
}
}else if (self.superUsers.contains(message.messageItem.senderId)){
return incomingAdminBubbleImageView
}else { // 3
if (message.approved == true){
return incomingBubbleImageView
}else{
return incomingUnnapprovedBubbleImageView
}
}
}
이것은 JS25MessageData 프로토콜에 나열된 messageBubbleImageDataForItemAt를 찾지 못했기 때문에 내가 가지고있는 것에 매우 가깝습니다. – Beland
아주 비슷한 것을 사용하고 있습니다. JSQMessageData 프로토콜을 따를 필요가 없습니다. messageBubbleImageDataForItemAt가 호출되어 첫 번째로드에서 나를 위해 작업하지만 리로드/일괄 업데이트 등에서 작동하지 않는 것 같습니다. – Beland
흥미로운 시간을 가졌을 때 나는 더 자세히 살펴 봐야 할 것입니다. –