The best approach that I found was to subclass JSQMessagesCollectionViewCellIncoming
and JSQMessagesCollectionViewCellOutgoing
. This is very important, because the library is expecting one of those types, you will run into trouble if you subclass from JSQMessagesCollectionViewCell
directly. BTW, I copied the existing JSQMessagesCollectionViewCellOutgoing.xib
, JSQMessagesCollectionViewCellIncoming.xib
and changed/renamed everything and this made it easier for me to start my customization of the cells.
Then in your JSQMessagesViewController subclass, register cell identifiers in your viewDidLoad() like so:
self.outgoingCellIdentifier = [CustomCollectionViewCellOutgoing cellReuseIdentifier];
self.outgoingMediaCellIdentifier = [CustomCollectionViewCellOutgoing mediaCellReuseIdentifier];
[self.collectionView registerNib:[CustomCollectionViewCellOutgoing nib] forCellWithReuseIdentifier:self.outgoingCellIdentifier];
[self.collectionView registerNib:[CustomCollectionViewCellOutgoing nib] forCellWithReuseIdentifier:self.outgoingMediaCellIdentifier];
self.incomingCellIdentifier = [CustomCollectionViewCellIncoming cellReuseIdentifier];
self.incomingMediaCellIdentifier = [CustomCollectionViewCellIncoming mediaCellReuseIdentifier];
[self.collectionView registerNib:[CustomCollectionViewCellIncoming nib] forCellWithReuseIdentifier:self.incomingCellIdentifier];
Then in collectionView:cellForItemAtIndexPath: you can access your custom cell:
[self.collectionView registerNib:[CustomCollectionViewCellIncoming nib] forCellWithReuseIdentifier:self.incomingMediaCellIdentifier];
Answer source link: https://github.com/jessesquires/JSQMessagesViewController/issues/1233