I\'m working on a project that loads list data from Firebase and populates a UITableView. While I see the snapshots being called from my firebase instance, they don\'t popul
With Firebase you have to keep in mind that all code (and, in particular, the blocks for the realtime updates) is asynchronously. For example, in the original question's comments as well as in the work-around answer, code like this:
[self loadDataFromFirebase];
[self.sampleTableView reloadData];
... can't be read from top to bottom; there will be a race condition between the data being populated (or views being updated) in the asynchronous blocks and the reloadData being called; maybe the cell connection is spotty, or GCD is optimizing for one thing over the other, and so on.
The second thing to keep in mind with Firebase is that for events like child_added there might not ever be any notion of "complete" — it's entirely possible for data to continually be shifting and updating; again, when would one expect reloadData to get called? Right away? After the first child? Last child? The implications of this are that if new data is added, even the work-around is going to yield behavior you're probably not expecting (i.e. it'll appear as if data isn't showing up because reloadData will never get called again.)
One approach you can take here would be to directly update your views as the data changes; so, your block would then look like:
[listRef observeEventType:FEventTypeChildAdded withBlock:^(FDataSnapshot *snapshot) {
NSLog(@"%@", snapshot.value);
[handles addObject:snapshot.value];
[self.sampleTableView reloadData];
}];
Another approach might be to use Firebase to exclusively update your internal models and use the regular Objective-C approaches (KVO, Notifications, MVC, etc) to separate your data and view concerns to rerender views outside of direct changes to your models.