2016-05-17 59 views
0

我有一個聊天應用程序,其中我想在新的聊天數據到來時將索引路徑增加一個。但它不是通過我的代碼發生我與屏幕快照分享代碼請幫助。在TableView(iOS)中將索引路徑移動一個

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

+0

我認爲你需要的是滾動tableview到底部。此鏈接可能會幫助你http://stackoverflow.com/questions/2770158/how-to-scroll-to-the-bottom-of-a-uitableview-on-the-iphone-before-the-view-appea – Tien

回答

0

下面的代碼可以讓你去最後indexpath與底部的滾動位置。

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

嘗試,讓我知道

+0

不是我們必須移動到最後一行。 –

+0

從最後一個可見行移動一行,就像whatsapp messeges來的一樣。 –

+0

檢查更新的代碼。邏輯背後,表中最後一行和滾動方向。 – Ramdy

0

我假設你已經處理的數據源更新部分,並正在更新的主線程表視圖。 您可以嘗試在底部這樣添加新行:

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]; 

你也可以有一些修改增加超過1行。

希望這會有所幫助。