0

I am new to iOS and i am working on chat application where i try to receive messages through XMPP and pass that received message to chat table view(UIBubbleTableView). But when i try to add that message in table view array the array becomes null, and hence the data does not gets added to table view.

When i try to store some hardcoded messages in that array in viewDidLoad method, it is showing those message on table view.

Below is my method which is invoked when there is a message received in XMPP class.

- (void)newMessageReceived:(NSString *)messageContent {

NSBubbleData *newdata = [NSBubbleData dataWithText: messageContent date:      [NSDate dateWithTimeIntervalSinceNow:0] type:BubbleTypeSomeoneElse];
bubbleData1=[[NSMutableArray alloc]init];
[bubbleData1 addObject:newdata];
_bubbleTable.bubbleDataSource=self;

      [_bubbleTable reloadData];

}

and above method receives data using XMPP method given below-

- (void)xmppStream:(XMPPStream *)sender didReceiveMessage:(XMPPMessage *)message {



NSString *msg = [[message elementForName:@"body"] stringValue];
NSString *from = [[message attributeForName:@"from"] stringValue];

NSMutableDictionary *m = [[NSMutableDictionary alloc] init];
[m setObject:msg forKey:@"msg"];
[m setObject:from forKey:@"sender"];

ChatController *chat=[[ChatController alloc]init];
[chat newMessageReceived:[m valueForKey:@"msg"]];

}

I am able to get the new message in newMessageRecieved method, but is does not get added to bubble tableview. Can anyone help me out to solve this problem. Any help is appreciated.

1 Answers1

0

You have to implement tableView:cellForRowAtIndexPath:.

In there you should add your content to the UITableViewCell or a custom subclass of it and then it displays the cells.

Tutorial

adrian
  • 266
  • 1
  • 10