FUITableViewDataSource
FUITableViewDataSource
implements the UITableViewDataSource
protocol to automatically use Firebase as a data source for your UITableView
.
Swift
self.dataSource = self.tableView.bind(to: query) { tableView, indexPath, snapshot in
// Dequeue cell
let cell = tableView.dequeueReusableCell(withIdentifier: "reuseIdentifier", for: indexPath)
/* populate cell */
return cell
}
Objective-C
self.dataSource = [self.tableView bindToQuery:query
populateCell:^UITableViewCell *(UITableView *tableView,
NSIndexPath *indexPath,
FIRDataSnapshot *snap) {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuseIdentifier"
forIndexPath:indexPath];
/* populate cell */
return cell;
}];
FUICollectionViewDataSource
FUICollectionViewDataSource
implements the UICollectionViewDataSource
protocol to automatically use Firebase as a data source for your UICollectionView
.
Swift
self.dataSource = self.collectionView.bind(to: self.firebaseRef) { collectionView, indexPath, snap in
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "reuseIdentifier", for: indexPath)
/* populate cell */
return cell
}
Objective-C
self.firebaseRef = [[FIRDatabase database] reference];
self.dataSource = [self.collectionView bindToQuery:self.firebaseRef
populateCell:^UICollectionViewCell *(UICollectionView *collectionView,
NSIndexPath *indexPath,
FIRDataSnapshot *object) {
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"reuseIdentfier"
forIndexPath:indexPath];
/* populate cell */
return cell;
}];
Using the Default Table/Collection View Cell
You can use the default UITableViewCell
or UICollectionViewCell
implementations to get up and running quickly. For UITableViewCell
s, this allows for the cell.textLabel
and the cell.detailTextLabel
to be used directly out of the box. For UICollectionViewCell
s, you will have to add subviews to the contentView in order for them to be useful.
Swift
self.dataSource = self.tableView.bind(to: firebaseRef) { tableView, indexPath, snap in
let cell = tableView.dequeueReusableCell(withIdentifier: "reuseIdentifier", for: indexPath)
// Populate cell as you see fit, like as below
cell.textLabel?.text = snap.key
return cell
}
self.dataSource = self.collectionView.bind(to: firebaseRef) { collectionView, indexPath, snap in
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "reuseIdentifier", for: indexPath)
// Populate cell as you see fit
cell.contentView.accessibilityLabel = "A cell"
return cell
}
Objective-C
self.dataSource = [self.tableView bindToQuery:self.firebaseRef
populateCell:^UITableViewCell *(UITableView *tableView,
NSIndexPath *indexPath,
FIRDataSnapshot *snap) {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuseIdentifier"
forIndexPath:indexPath];
// Populate cell as you see fit, like as below
cell.textLabel.text = snap.key;
return cell;
}];
self.dataSource = [self.collectionView bindToQuery:self.firebaseRef
populateCell:^UICollectionViewCell *(UICollectionView *collectionView,
NSIndexPath *indexPath,
FIRDataSnapshot *snap) {
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"reuseIdentifier"
forIndexPath:indexPath];
// Populate cell as you see fit
cell.contentView.accessibilityLabel = @"A cell";
return cell;
}];