1

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.

halfer
  • 19,824
  • 17
  • 99
  • 186
  • This line NSLog(@" tapped cell data - %@",[newMessageArray objectAtIndex: tapIndexPath.row]); will always return the object you have stored in your array. Show us what object is stored in array may i able to help you then. – Devang Tandel Oct 14 '16 at 09:48
  • NSBubbleData *sayBubble = [NSBubbleData dataWithText:_txtchat.text date:[NSDate dateWithTimeIntervalSinceNow:0] type:BubbleTypeMine]; [newMessageArray addObject:sayBubble]; Here _txtchat is my textfield from where i am sending the text. – Amuuu Gaikwad Oct 14 '16 at 09:59
  • if you store NSBubbleData in your array you are gone get same try this may this work for you to display what is inside NSBubbledata *test = [newMessageArray objectAtIndex: tapIndexPath.row]; NSLog(@" result: ",test); – Devang Tandel Oct 14 '16 at 10:24
  • ok. i'll try it – Amuuu Gaikwad Oct 14 '16 at 10:25
  • it still displays the same thing- . Actually nsbubbledata is my NSObject class and [dataWithText : date: type] is its method where is pass the data. can you please help me what wrong am i doing – Amuuu Gaikwad Oct 14 '16 at 10:30
  • if you want to detect type of message i would suggest you to add mediaType filed in your Object, this will save lots of traversing for CPU. – Devang Tandel Oct 14 '16 at 10:38
  • I have worked on 2 Chat application so far, so if i were you i would have gone with adding One filed. – Devang Tandel Oct 14 '16 at 10:39
  • Thanks for you time and suggestions . It helps to learn a lot. – Amuuu Gaikwad Oct 14 '16 at 10:44

2 Answers2

1

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
            }
        }
    }
}
  • Can you help me with one more question. I am not able to add labels and view on chat bubble, like time format date, etc at the bottom of each bubble. Could you please help me with this?? please. – Amuuu Gaikwad Oct 18 '16 at 14:26
  • @AmuuuGaikwad yes sure, can you add another question, so i can see your code for labels and view which you want to add in bottom of each bubble. – Chirag D jinjuwadiya Oct 19 '16 at 09:06
  • @ChiragDjinjuwadiya- can you please refer this question, i have added on stack overflow - [adding subview to chat bubble (cell) in iOS]. – Amuuu Gaikwad Oct 19 '16 at 09:13
0

In the Alex Barinovs chat bubble table view they have used NSBubbleData as an object to maintain the values. When you select any of the cell you will get the NSBubbleData object i. I hope you are constructing the NSBubbleData array with your values. By getting the cell indexPath you can get your values from the array you used for constructing the NSBubbleData.

In the NSBubbleData object you can't get the text, image. But you can get the Date, type and view.

Abha
  • 1,032
  • 1
  • 13
  • 36
Yogesh Mv
  • 1,041
  • 1
  • 6
  • 12