Search code examples
iosobjective-ciphoneuitableviewuibubbletableview

Reading NSBubbledata on Bubble Tableview cell tap


I'm working on a chat application where I'm using Alex Barinovs chat bubble table view example. I'm able to add messages and images on the bubbles. But What I want is when I tap on any row or cell, I want to get the details of that particular cell I tapped. I have a method called onListTap , which is a UItapGestureRecognizer method, I'm able to get the index path of table view on tap. But the data it returns on that cell is somewhat like this-

    tapped cell data - <NSBubbleData: 0x7fe6c3160f10>

Can anyone please tell me how to read this (NSBubbleData) data and how to identify which type of data it is (image, text, view ,etc).

Here is my onListTap method:

- (void)onListTap:(UIGestureRecognizer*)recognizer {
if (recognizer.state == UIGestureRecognizerStateEnded) {
    CGPoint tapLocation = [recognizer locationInView:_bubbleTable];
    NSIndexPath *tapIndexPath = [_bubbleTable indexPathForRowAtPoint:tapLocation];
        NSLog(@" tapped cell data - %@",[newMessageArray objectAtIndex: tapIndexPath.row]);

}
}

where, newMessageArray is my bubble tableview array.


Solution

  • Check this, i think it will work. you can get text and Image which is in cell Don't forgot to #import "UIBubbleTableViewCell.h"

    - (void)onListTap:(UIGestureRecognizer*)recognizer {
        if (recognizer.state == UIGestureRecognizerStateEnded) {
            CGPoint tapLocation = [recognizer locationInView:_bubbleTable];
            NSIndexPath *tapIndexPath = [_bubbleTable indexPathForRowAtPoint:tapLocation];
            UIBubbleTableViewCell *cell = [_bubbleTable cellForRowAtIndexPath:tapIndexPath];
            for (id Obj in cell.contentView.subviews) {
                if ([Obj isKindOfClass:[UILabel class]]) {
                    UILabel *Lbl = (UILabel *)Obj;
                    NSLog(@"%@",Lbl.text);
                }
                if ([Obj isKindOfClass:[UIImageView class]]) {
                    UIImageView *Img = (UIImageView *)Obj;
                    //Do Something with Img.image
                }
            }
        }
    }