0

I have a chat application, in which i want to increase the index path by one when new chat data come. But it is not happening through my code I am sharing code with screen shot please help.

NSUInteger messageCount = [self numberOfMessages];

if (self.conversation && messageCount > 0) {
    NSLog(@"%ld",(long)indexPathValue.row);
    NSIndexPath* ip = [NSIndexPath indexPathForRow:indexPathValue.row + 1 inSection:0];
    NSLog(@"%ld",(long)ip.row);
    [layerChatTableView scrollToRowAtIndexPath:ip atScrollPosition:UITableViewScrollPositionTop animated:YES];
}

enter image description here

Daniel
  • 20,420
  • 10
  • 92
  • 149
Nazish Ali
  • 320
  • 3
  • 16
  • I think what you need is scroll tableview to bottom. This link may help you http://stackoverflow.com/questions/2770158/how-to-scroll-to-the-bottom-of-a-uitableview-on-the-iphone-before-the-view-appea – Tien May 17 '16 at 10:29

2 Answers2

0

Below code allows you to go last indexpath with scroll position of bottom.

[tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:messageCoutnt-1 inSection:0] atScrollPosition:UITableViewScrollPositionButtom animated:NO];

Try and let me know

Ramdhas
  • 1,765
  • 1
  • 18
  • 26
0

I am assuming that you have handled the datasource updating part and that you are updating the table view on main thread. You can try to add new row at bottom like this:

NSInteger section = 0;
NSInteger newCount = [self tableView:self.tableView numberOfRowsInSection:section];
NSMutableArray *paths = @[].mutableCopy;
[paths addObject:[NSIndexPath indexPathForRow:newCount inSection:section]];
[self.tableView beginUpdates];
[self.tableView insertRowsAtIndexPaths:paths withRowAnimation:UITableViewRowAnimationNone];
[self.tableView endUpdates];

You can also add more than 1 row with some modifications.

Hope this helps.

Nameet
  • 650
  • 8
  • 20