ammy1 ammy1 - 1 year ago 90
iOS Question

creating a bubble in UITableView for chat application in iOS

I am trying to create a

in my
. I searched an example on the internet and tried exactly the same thing. But the example used xib, and i am using
I have imported the file given in example in my project. But when i try to run that code, it gets crashed saying.-

-[UITableView setBubbleDataSource:]: unrecognized selector sent to instance

Here below is what i tried.

@interface ChatController (){

IBOutlet UIView *textView;
IBOutlet UITextField *textF1;
NSMutableArray *bubbleData1;
IBOutlet UIBubbleTableView *bubbleTbl;

-(void)viewDidLoad {
[super viewDidLoad];

//bubble data
NSBubbleData *heyBubble1 = [NSBubbleData dataWithText:@"Hey, halloween is soon" date:[NSDate dateWithTimeIntervalSinceNow:-300] type:BubbleTypeSomeoneElse];
heyBubble1.avatar = [UIImage imageNamed:@"avatar1.png"];

NSBubbleData *photoBubble1 = [NSBubbleData dataWithImage:[UIImage imageNamed:@"halloween.jpg"] date:[NSDate dateWithTimeIntervalSinceNow:-290] type:BubbleTypeSomeoneElse];
photoBubble1.avatar = [UIImage imageNamed:@"avatar1.png"];

NSBubbleData *replyBubble1 = [NSBubbleData dataWithText:@"Wow.. Really cool picture out there. iPhone 5 has really nice camera, yeah?" date:[NSDate dateWithTimeIntervalSinceNow:-5] type:BubbleTypeMine];
replyBubble1.avatar = nil;

bubbleData1 = [[NSMutableArray alloc] initWithObjects:heyBubble1, photoBubble1, replyBubble1, nil];
bubbleTbl.bubbleDataSource = self;

the app crashes on this line. -
bubbleTbl.bubbleDataSource = self

I tried to connect the 'bubbleTbl' outlet to my
, But couldn't connect it hence i don't know how to 'set
' to my

Can anyone please help me out. Any help is appreciated


I have implemented this method and have set a breakpoint on this method. But this method never gets executed.

- (NSInteger)rowsForBubbleTable:(UIBubbleTableView *)tableView

NSLog(@"bubble count %lu",(unsigned long)[bubbleData1 count]);
return [bubbleData1 count];


code for showing video in bubble-

UIEdgeInsets insetss = { .left = 180, .right = 10, .top =10, .bottom = 200 };
NSBubbleData *videodata=[NSBubbleData dataWithView:_playerViewController.view date:[NSDate dateWithTimeIntervalSinceNow:0] type:BubbleTypeMine insets:(insetss)];
[bubbleData1 addObject:videodata];

EDIT 3--

NSString *stringVideoName = @"";
NSString *stringVideoPath = [[NSBundle mainBundle] pathForResource:stringVideoName ofType:nil];
NSAssert(stringVideoPath, @"Expected not nil video file");

NSURL *urlVideoFile = [NSURL fileURLWithPath:stringVideoPath];
NSAssert(urlVideoFile, @"Expected not nil video url");

_playerViewController = [[AVPlayerViewController alloc] init];
_playerViewController.player = [AVPlayer playerWithURL:urlVideoFile];
_playerViewController.view.frame = CGRectMake(10.0, 0.0, 150.0 , 80.0); // self.view.bounds;
_playerViewController.showsPlaybackControls = YES;

Answer Source

Add in xib/storyboard to UITableView in class - UIBubbleTableView

enter image description here