2

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;
Borys Verebskyi
  • 4,160
  • 6
  • 28
  • 42
Philip Sopher
  • 627
  • 2
  • 8
  • 19
  • This won't affect the view. iOS only draws the amount of cells needed for the page, hence `dequeueReusableCellWithIdentifier`. You may have issues with larger data sets though because of the download time. How big is your expected data set? – David East Dec 21 '15 at 20:55
  • So far the data sets are fairly small. The tableviews have between 2 and 10 observations apiece. They load fairly quickly up to 5 observations, but then it gets much slower after that. The main reason it's so slow after so few observations is that each tableview cell includes a picture, which seems to slow it down a bit. Though the data sets are small now, I'm expecting them to get much bigger—into the hundreds or thousands. If it's slow with 10 observations, it'll be way too slow with 100. I can't limit them to first or last because they need to be sorted by one of the children. @DavidEast – Philip Sopher Dec 21 '15 at 21:03
  • Ah! And I take it you have you images stored as the url to the image? – David East Dec 21 '15 at 21:06
  • @DavidEast, the images are stored as NSStrings, not the URL strings – Philip Sopher Dec 21 '15 at 21:07
  • @DavidEast yes, I've edited the question to show the code I use for retrieving the images – Philip Sopher Dec 21 '15 at 21:17
  • should be a question related more to FireBase than iOS – Lucas Huang Dec 21 '15 at 21:24
  • @DavidEast is there a way people generally populate tableviews of images from large data sets using Firebase? – Philip Sopher Dec 21 '15 at 21:37

1 Answers1

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.

Community
  • 1
  • 1
tfrank377
  • 1,858
  • 2
  • 22
  • 34