我有一个扩展JSQMessagesViewController的ChatViewController。
final class ChatViewController: JSQMessagesViewController {
...
override func viewDidLoad() {
super.viewDidLoad()
title = "Messages"
collectionView?.collectionViewLayout.incomingAvatarViewSize = .zero
collectionView?.collectionViewLayout.outgoingAvatarViewSize = .zero
automaticallyScrollsToMostRecentMessage = true
collectionView?.reloadData()
collectionView?.layoutIfNeeded()
collectionView?.collectionViewLayout.springinessEnabled = true
// REMOVE the attachment button for now
self.inputToolbar.contentView?.leftBarButtonItem = nil
self.inputToolbar.contentView?.textView?.placeHolder = "Compose a message to your driver"
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
observeMessages()
}
private func observeMessages() {
messageRef = channelRef!.child("messages")
let messageQuery = messageRef.queryLimited(toLast:25)
newMessageRefHandle = messageQuery.observe(.childAdded, with: { (snapshot) -> Void in
let messageData = snapshot.value as! Dictionary<String, String>
if let id = messageData["senderId"] as String!, let name = messageData["senderName"] as String!, let text = messageData["text"] as String!, text.characters.count > 0 {
self.addMessage(withId: id, name: name, text: text)
self.finishReceivingMessage()
} else {
print("Error! Could not decode message data")
}
})
}
}
此视图控制器由具有导航控制器的push segue调用。在我的故事板中,我有一个来自条形项按钮的简单segue,它将推送到View Controller,并将ChatViewController设置为自定义类。在故事板中,推断出导航栏(显示在顶部)。
然而,当我进入ChatViewController时,消息显示在导航栏下方。单击消息文本框后,消息将正确定位。如何解决此问题,以便用户无需单击文本框?是否缺少正确布置新消息的命令?