ios – 如何正确插入底部的行后滚动tableview?

ios – 如何正确插入底部的行后滚动tableview?,第1张

概述这是我使用的代码: //inserting a row at the bottom first_numberOfRecords++;[_tableView beginUpdates];[_tableView insertRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:_numberOfRecords-1 inSection:0]] withRo 这是我使用的代码:

//inserting a row at the bottom first_numberOfRecords++;[_tableVIEw beginUpdates];[_tableVIEw insertRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:_numberOfRecords-1 inSection:0]] withRowAnimation:UItableVIEwRowAnimationBottom];[_tableVIEw endUpdates];//clear text_inputFIEld.text = @"";//then scroll to bottomCGPoint bottomOffset = CGPointMake(0,_tableVIEw.contentSize.height + 44.0 + _tableVIEw.contentInset.top - _tableVIEw.bounds.size.height);NSLog(@"%f",_tableVIEw.contentSize.height + 44.0 + _tableVIEw.contentInset.top - _tableVIEw.bounds.size.height);[_tableVIEw setContentOffset:bottomOffset animated:YES];

这将以非常奇怪的方式滚动tablevIEw.
但是如果我在插入之前插入滚动代码,它会正常工作,除非它忽略了最新插入的行.也就是说,它滚动到倒数第二行而不是滚动到最后一行(当然,因为它在插入新卷之前滚动.)

所以我相信这段代码没有问题,它应该滚动到的位置.
问题可能来自行插入到tablevIEw.
它违反了滚动表格视图的动画.

我这样做是为了聊聊天.
每次用户发送或接收消息时,我都会将包含该消息的行插入表视图,并将其滚动到底部.这就是我在这里使用tableVIEw的原因.我尝试使用带有标签的scrollVIEw,它工作正常,但tableVIEw在聊天视图中似乎更受欢迎.

我在想使用scrollVIEw或tableVIEw,我发现Apple的内置消息应用程序正在使用tableVIEw,所以我采用了tableVIEw.如果带有Label的scrollVIEw比tableVIEw更好,请告诉我.

无论如何,如何在插入新行后将tableVIEw滚动到底部?

解决方法 尝试使用UItableVIEw的scrollToRowAtIndexPath ::

[self.tableVIEw scrollToRowAtIndexPath: atScrollposition: animated:];
总结

以上是内存溢出为你收集整理的ios – 如何正确插入底部的行后滚动tableview?全部内容,希望文章能够帮你解决ios – 如何正确插入底部的行后滚动tableview?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1078624.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-27
下一篇2022-05-27

发表评论

登录后才能评论

评论列表(0条)

    保存