Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSQMessageViewController - How do I set a collection cell to be incoming or outgoing cell?

enter image description here

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;
}
like image 399
Atilla Jax Avatar asked Dec 31 '25 10:12

Atilla Jax


1 Answers

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

like image 133
Atilla Jax Avatar answered Jan 02 '26 01:01

Atilla Jax