Atilla Jax Atilla Jax - 1 year ago 82
iOS Question

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

? 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;

Answer Source

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";
        senderID = @"sender";

This works and solved my problem.

Many thanks all

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download