Populating a UITableView in Firebase a Set Number of Cells at a time

心已入冬 提交于 2019-12-11 00:09:58

问题


I am using Firebase to populate a UITableView.

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.

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.

Any advice?

--EDIT

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;

回答1:


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.

Existing Solution

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.

Final Thought

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.



来源:https://stackoverflow.com/questions/34403886/populating-a-uitableview-in-firebase-a-set-number-of-cells-at-a-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!