每当我尝试向JSQMessages数组附加消息时,它都不会出现在collectionView的末尾
错误演示:http://www.giphy.com/gifs/l0ExjQLlFmIH9MGQg
我的检索邮件的代码:
func retrieveMessages() {
let messagesRef = databaseRef.child("messages")
var senderID : String!
var recieverID : String!
var message : JSQMessage!
messagesRef.observe(.value, with: { (snapshot) in
if let dictionary = snapshot.value as? [String : AnyObject] {
self.messages.removeAll()
for each in dictionary {
let mediaType = each.value["mediaType"] as! String
let text = each.value["text"] as! String
let senderDisplayName = each.value["senderDisplayName"] as! String
senderID = each.value["senderID"] as! String
recieverID = each.value["reciverID"] as! String
let time = each.value["time"] as! Int
message = JSQMessage(senderId: senderID, displayName: senderDisplayName, text: text)
if senderID == FIRAuth.auth()?.currentUser?.uid {
if recieverID == self.userUID {
self.messages.append(message)
self.collectionView.reloadData()
}
}
}
}
我的发送邮件的代码:
override func didPressSend(_ button: UIButton!, withMessageText text: String!, senderId: String!, senderDisplayName: String!, date: Date!) {
JSQSystemSoundPlayer.jsq_playMessageSentSound()
finishSendingMessage(animated: true)
let newMessage = messagesRef.childByAutoId()
let currentTime = Date()
let currentTimePassed = currentTime.timeIntervalSince1970
let timeInt = Int(currentTimePassed)
let messageData = ["text" : text, "senderID" : senderId, "senderDisplayName" : senderDisplayName, "mediaType" : "TEXT", "reciverID" : userUID, "time" : timeInt] as [String : Any]
newMessage.setValue(messageData)
}