我收到消息后重新加载了表格。
这是代码:
[self.tblChatting beginUpdates];
NSIndexPath *newIndexPath = [NSIndexPath indexPathForRow:app.Glb.arrayChat.count-1 inSection:0];
[self.tblChatting insertRowsAtIndexPaths:[indexPaths copy] withRowAnimation:UITableViewRowAnimationBottom];
[self.tblChatting endUpdates];
[self.tblChatting reloadData];
[self.tblChatting scrollToRowAtIndexPath:newIndexPath
atScrollPosition:UITableViewScrollPositionBottom
animated:YES];
这是我的表视图对象细节,当动画不在那里而我的行没有添加到表中时:
<UITableView: 0x18bece00; frame = (0 55; 250 351); clipsToBounds = YES; autoresize = W+H; gestureRecognizers =
<NSArray: 0x17ec5fb0>; layer = <CALayer: 0x17ec5150>; contentOffset: {0, 6541}; contentSize: {250, 6892.0312}>
这里是在对象中添加了succesfull和animatoin的行时的表视图对象:
<UITableView: 0x14949e00; frame = (0 55; 320 351); clipsToBounds = YES; autoresize = W+H; gestureRecognizers = <NSArray: 0x14665210>; animations = { position=<CASpringAnimation: 0x1a75d9f0>; bounds.origin=<CASpringAnimation: 0x1a4e9d20>; bounds.size=<CASpringAnimation: 0x1ac4b980>;
bounds.origin-2=<CASpringAnimation: 0x1a1fbb40>; bounds.size-2=<CASpringAnimation: 0x1a1b02d0>; };
layer = <CALayer: 0x145f1300>; contentOffset: {0, 6593}; contentSize: {320, 6944.1309}>
有时只会发生。 为什么会这样?
答案 0 :(得分:0)
删除
行[self.tblChatting reloadData];
insertRowsAtIndexPaths
隐式重新排列表格视图。
同时删除begin/endUpdates
行。它们对单个插入操作没有影响。
答案 1 :(得分:0)
您可以在表格视图中插入行并重新加载表格:
试试这个:
NSIndexPath *newIndexPath = [NSIndexPath indexPathForRow:app.Glb.arrayChat.count-1 inSection:0];
[self.tblChatting insertRowsAtIndexPaths:@[indexPaths] withRowAnimation:UITableViewRowAnimationBottom];
[self.tblChatting scrollToRowAtIndexPath:newIndexPath
atScrollPosition:UITableViewScrollPositionBottom
animated:YES];