I was trying to implement MessageKit (Replacement of JSQMessagesViewController) for chat feature, in my iOS swift application. I have followed this raywenderlich tutorial. I installed using Pods and followed this tutorial step by step. My messages are showing. According to this tutorial, for hiding the user avatar, i set my viewController to be delegate of messagesLayoutDelegate
and messagesDisplayDelegate
.
//Inside view did load, i set the delegates, along with data source
messagesCollectionView.messagesDataSource = self
messagesCollectionView.messagesLayoutDelegate = self
messagesCollectionView.messagesDisplayDelegate = self
However, the delegate functions of MessagesLayoutDelegate
are not being called.
I wanted to hide user avatar so i adopted the protocols in my viewController
extension ChatLogVC_MessageKit: MessagesLayoutDelegate {
func avatarSize(for message: MessageType, at indexPath: IndexPath,
in messagesCollectionView: MessagesCollectionView) -> CGSize {
//return zero size for hiding avatar, but this function is not being called.
return .zero
}
func footerViewSize(for message: MessageType, at indexPath: IndexPath,
in messagesCollectionView: MessagesCollectionView) -> CGSize {
//also not being called
return CGSize(width: 0, height: 8)
}
}
I have set break points inside these functions but the break points never hit. Morever, the shouldDisplayHeader
function of MessagesDisplayDelegate
is also not being called
Any help would be much appreciated
Note: I have tested it on simulator only.
Your delegate methods look outdated. If you are using Cocoa pods, at least use the 1.0.0 beta 1 version:
pod 'MessageKit', '1.0.0-beta.1'
Or, better, use the 1.0.0 version:
pod 'MessageKit', '1.0.0'
In your viewDidLoad()
method set the delegate:
messagesCollectionView.messagesDataSource = self
messagesCollectionView.messagesLayoutDelegate = self
messagesCollectionView.messagesDisplayDelegate = self
messagesCollectionView.messageCellDelegate = self
By the way, the avatar size is set in the MessagesDisplayDelegate method func configureAvatarView(_ avatarView: AvatarView, for message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView)
.
Checkout the Example in the Library
https://github.com/MessageKit/MessageKit/tree/master/Example
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With