将数据逐个加载到 UICollectionView 中 [英] Loading data into UICollectionView bunch by bunch

查看:24
本文介绍了将数据逐个加载到 UICollectionView 中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个聊天应用程序,但我的集合视图有问题.在我的应用程序中,我只想做一些类似 whatsapp 的事情,一开始我加载前 50 条消息,当我们向下滚动时,我想逐个获取其他消息.但是当我这样做并调用集合视图 reloadData 方法时,它会滚动到顶部消息.我不希望他们滚动.你能帮助我吗.请..

I am building an chat app and I have a problem with the collection view. In my app I just want to do something like whatsapp, in starting I load the first 50 messages and when we scroll down then want to fetch other messages bunch by bunch. But when I doing this and call the collection view reloadData method then it scroll to the top message. And I don't want they scrolling. Can you help me. Please..

我只是想让 collectionView 类似于 whatsapp 的聊天视图......即当用户滚动到旧消息时加载更多消息.

I just simply want to make the collectionView similar to whatsapp's chat view.. i.e. load more messages when user scroll to the older messages.

推荐答案

您所要求的只是将单元格送入(插入)到集合视图中,而无需重新加载.

What you are asking for is just feeding (inserting) cell into collection view without reloading it.

在插入项目时检查此 appledoc.

Check this appledoc, on inserting item.

确定新的 indexPaths,然后使用以下方法将其提供给集合视图

determine the new indexPaths and then feed it to collection view using following

yourCollectionView.insertItems(at indexPaths: newIndexPaths)

这篇关于将数据逐个加载到 UICollectionView 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆