1

I'm trying to add a topLabel to the JSQMessageCollectionViewCell and am implementing the correct method, but nothing is showing up. Here is my code:

override func collectionView(collectionView: JSQMessagesCollectionView!, attributedTextForMessageBubbleTopLabelAtIndexPath indexPath: NSIndexPath!) -> NSAttributedString! {

    let msg: JSQMessage = self.JSQmessages[indexPath.item]
    if (msg.senderId != self.senderId) {

        return NSAttributedString(string: "Tester")
    }
    else {
        return NSAttributedString(string: senderDisplayName)
    }

}

Additionally, I am trying to add the date label by tapping on a given message collection cell. How should I go about doing this? I am adding an NSDate as part of each JSQMessage.

Sampath Duddu
  • 277
  • 1
  • 5
  • 14

1 Answers1

3

You need to return a height for the top label by implementing:

- (CGFloat)collectionView:(JSQMessagesCollectionView *)collectionView
                   layout:(JSQMessagesCollectionViewFlowLayout *)collectionViewLayout heightForCellTopLabelAtIndexPath:(NSIndexPath *)indexPath;

In order to show the label on tap, you'll need to store the selected indexPath, and return a height for that indexPath in the above method.

hwaxxer
  • 3,363
  • 1
  • 22
  • 39