3

I've been trying to figure out how to insert a handler to take action when a user taps on the message bubble. I've found the section in the readme about "customize your cells" and have tried a couple of different approaches, but so far no luck. Here's what I've tried:

Implemented:

- (void)collectionView:(JSQMessagesCollectionView *)collectionView didTapMessageBubbleAtIndexPath:(NSIndexPath *)indexPath

in my viewController as:

override func collectionView(collectionView: JSQMessagesCollectionView, didTapMessageBubbleAtIndexPath indexPath: NSIndexPath!) {
    super.collectionView(collectionView, didTapMessageBubbleAtIndexPath: indexPath)
    println("They tapped!")
}

However, this doesn't seem to get called at all for some reason.

The other thing I've tried is implementing:

- (UICollectionViewCell *)collectionView:(JSQMessagesCollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath

In my view controller as:

override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
    let cell = super.collectionView(collectionView, cellForItemAtIndexPath: indexPath) as! JSQMessagesCollectionViewCell

    let myDelegate = MyJSQMessagesCollectionViewCellDelegate(origDelegate: cell.delegate!)
    cell.delegate = myDelegate

    return cell;
}

This gets called, but the methods in my delegate don't get invoked.

So, any suggestions on how I can properly get my JSQMessagesCollectionViewCellDelegate put in place so that it gets invoked? Or is my initial attempt to just override the didTapMessageBubbleAtIndexPath method the proper way to go?

Any suggestions are appreciated.

Silviu St
  • 1,810
  • 3
  • 33
  • 42

1 Answers1

2

OK, I got it figured out. My attempt to insert my own delegate was actually breaking things (in addition to not accomplishing what I tried to do). Once I removed my "cellForItemAtIndexPath" method my "didTapMessageBubbleAtIndexPath" started firing.

  • Scott, I'm trying to implement this to open a media message into a new view controller. Would you mind sharing a little of your code for didTapMessageBubble...? Thanks so much! – Robert Oct 16 '15 at 23:20
  • 1
    Hi @Robert, not sure if this will help, but here's the gist of my method that handles the tap: override func collectionView(collectionView: JSQMessagesCollectionView!, didTapMessageBubbleAtIndexPath indexPath: NSIndexPath!) { super.collectionView(collectionView, didTapMessageBubbleAtIndexPath: indexPath) var data = self.messages[indexPath.row] println("They tapped '\(data.text)'") } – Scott Mitchell Oct 20 '15 at 23:06
  • @Robert, I can't figure out how to format the comment, but hopefully you get the gist. – Scott Mitchell Oct 20 '15 at 23:09
  • @Robert How to play a video using JSQMessageViewController??If i Add it shows video message and am not able to download and play a video.....How to do this??I have commented didReceiveMessage method from DemoMessageViewController??? –  May 11 '16 at 10:52