Using the JSQMessage podfile for iOS, in this method;
collectionView:(JSQMessagesCollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { .. }
How do I set the it to use JSQMessagesCollectionViewCellIncoming
or JSQMessagesCollectionViewCellOutgoing
? I am finding it diffcult to find examples of how other apps do this
My code;
- (UICollectionViewCell *)collectionView:(JSQMessagesCollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
JSQMessagesCollectionViewCell *cell = (JSQMessagesCollectionViewCell*)[super collectionView:collectionView cellForItemAtIndexPath:indexPath];
[cell.textView setDataDetectorTypes:UIDataDetectorTypeNone];
cell.textView.text = nil;
VICChatMessage <JSQMessageData> *messageData = (VICChatMessage*)[collectionView.dataSource collectionView:collectionView messageDataForItemAtIndexPath:indexPath];
cell.textView.attributedText = messageData.attributedText;
return cell;
}
I was able to solve the problem. It was to do with the sender details.
By default its JSQDefaultSender
but my code was only setting it if it knew the sender; so I used a fallback for when the sender was not known.
The idea is to get the
BOOL isOutgoingMessage = [messageSender isEqualToString:self.sender];
inside the podfile: JSQMessagesViewController.m
So that it positions them either on the left or right.
In the end I had to do this in my code where I obtain my message ready for display
if (message.sender.remoteID)
{
senderID = @"JSQDefaultSender";
}
else
{
senderID = @"sender";
}
This works and solved my problem.
Many thanks all