问题
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 NSString
s. Here is the code I use to retrieve them and turn them into UIImage
s
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