MessageKit不显示消息输入栏Swift 5 [英] MessageKit Not Showing Message Input Bar Swift 5

查看:134
本文介绍了MessageKit不显示消息输入栏Swift 5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以这是控制器层次结构tabBarController->一些控制器&聊天频道控制器.

So This is the controller hierarchy tabBarController -> some controller & chat channel controller.

,此聊天频道控制器也是导航控制器.当我选择行时,它会推送到MessageViewController类的聊天控制器.

and this chat channel controller is also a navigation controller. When I select row it pushes to chat controller which is of class MessageViewController.

我这里有2个问题,其中1个是辅修专业.

I have 2 issues here one minor one major.

次要角色是头像.

    func avatarSize(for message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> CGSize {
        print("delegate method called")
        return .zero
}

我在其中一个代表中将其设置为零,但它仍然显示.而且它从不打印该语句.

I set it to zero in one of the delegates but it still shows.And also it never prints the statement.

主要的一点是输入栏根本没有显示.我的Pod文件中已经有InputBarAccessoryView和

major one is that the input bar is not showing at all. I already have InputBarAccessoryView in my pod file and

messageInputBar.delegate = self as InputBarAccessoryViewDelegate

extension ChatViewController: InputBarAccessoryViewDelegate {

    func inputBar(_ inputBar: InputBarAccessoryView, didPressSendButtonWith text: String) {
        print("text")
    }

}

但没有任何显示.我还检查了视图,但找不到

but nothing shows. I also checked the views and I couldn't find it

推荐答案

为解决此问题,我必须:

to resolve this I had to :

导入InputBarAccessoryView

所以您不必这样做:

messageInputBar.delegate = self作为InputBarAccessoryViewDelegate

并在您的viewDidLoad()中设置这些委托(颜色可选)

and in your viewDidLoad() set these delegates(colors optional)

        super.viewDidLoad()
         guard let userId = Auth.auth().currentUser?.uid else{return}
        Database.fetchUserWithUID(uid: userId) { (user) in
            self.currentLogginUser =  user
        }
        messageInputBar.delegate = self
        maintainPositionOnKeyboardFrameChanged = true
        messageInputBar.inputTextView.tintColor = .yellow
        messageInputBar.sendButton.setTitleColor(.purple, for: .normal)

        messagesCollectionView.messagesDataSource = self
        messagesCollectionView.messagesLayoutDelegate = self
        messagesCollectionView.messagesDisplayDelegate = self
        messagesCollectionView.messageCellDelegate = self

        messageInputBar.leftStackView.alignment = .center
        messageInputBar.setLeftStackViewWidthConstant(to: 50, animated: false)
    getMessages()
    }

然后使用实时数据库-Firebase

then if using Realtime Database - Firebase


    func inputBar(_ inputBar: InputBarAccessoryView, didPressSendButtonWith text: String) {
        guard let recipient = self.recipient else{return}
        guard let uid = Auth.auth().currentUser?.uid else{return}
        let ref = Database.database().reference().child("messages")
        let childRef = ref.childByAutoId()

        let values = ["sender": uid, "text": text, "recipient": recipient.uid, "time": Date().timeIntervalSince1970.description]
        childRef.updateChildValues(values) { (err, ref) in

            if let err = err{
                print(err)
                return
            }

            let userMessageRef = Database.database().reference().child("user-messages").child(uid).child(recipient.uid)

            //add chat id generated from AutoId
            guard let messageId = childRef.key else{return}
            userMessageRef.updateChildValues([messageId: 1])

            let recipientMessageRef = Database.database().reference().child("user-messages").child(recipient.uid).child(uid)
            recipientMessageRef.updateChildValues([messageId:1])
        }
        inputBar.inputTextView.text = ""

    }
}


这篇关于MessageKit不显示消息输入栏Swift 5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆