一次将一定数量的单元格填充到Firebase中的UITableView [英] Populating a UITableView in Firebase a Set Number of Cells at a time

查看:49
本文介绍了一次将一定数量的单元格填充到Firebase中的UITableView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Firebase填充 UITableView .

I am using Firebase to populate a UITableView.

我想知道Firebase是否有可能下载前5个结果,并且一旦用户滚动到其中的最后一个,就下载下5个结果.

I was wondering if it's possible to have Firebase download the first 5 results, and, once the user has scrolled to the last of these, download the next 5 results.

此刻,Firebase一次下载了我的所有子节点,但是如果逐位下载,视图将加载得更快.

At the moment, Firebase downloads all of my child nodes at once, but if it did it bit-by-bit, the view would load more quickly.

有什么建议吗?

-编辑

请务必注意,单元格中有图像.图像是base64编码的 NSString .这是我用来检索它们并将其转换为 UIImage s

It's important to note that there are images in the cells. The images are base64 encoded NSStrings. Here is the code I use to retrieve them and turn them into UIImages

NSString* profPicString = [child.value objectForKey: @"profilePicture"];
NSData *dataFromBase64 = [NSData base64DataFromString:profPicString];
UIImage *profPicImage = [[UIImage alloc]initWithData:dataFromBase64];
item.profilePicture = profPicImage;

推荐答案

初步思想

我不知道是否有理想的解决方案,但是我肯定会研究

Initial Thought

I don't know if there is an ideal solution for this, but I would definitely look into complex queries in Firebase's documentation. You can query certain ranges by using the methods queryStartingAtValue and queryEndingAtValue, but you have to make sure your firebase is setup correctly to work with these.

在范围查询"部分的底部,它提到:

At the bottom of the Range Queries section, it mentions:

当您需要对数据进行分页时,范围查询也很有用.

Range queries are also useful when you need to paginate your data.

所以这可能是您理想的解决方案.

So this might be your ideal solution.

有一个 answer 我发现它使用了我上面提到的内容,因此希望它对您有用.我要补充一点,在我的Firebase上使用这些范围查询方法并没有多少运气.

There is an answer I found that uses what I mentioned above so hopefully it works for you. I will add, I haven't had much luck using these range query methods on my firebase.

另一种解决方案可能不是您想要听到的答案,但是(希望)URL比base64编码的图像短很多,并且在处理大量数据时下载时间可能会有很大不同.使用此实现,您仅在需要时才从服务器请求图像,而不是一次全部.

Another solution which is probably not the answer you want to hear, but a URL is (hopefully) a lot shorter than a base64 encoded image and could make a large difference in download times when dealing with a lot of data. With this implementation, you only ask for images from a server when you need them and not all at once.

这篇关于一次将一定数量的单元格填充到Firebase中的UITableView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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