Skip to content

Commit

Permalink
batch updates in tableviews
Browse files Browse the repository at this point in the history
  • Loading branch information
morganchen12 committed Jan 4, 2017
1 parent 4cf3b1e commit c51dec1
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions FirebaseDatabaseUI/FUITableViewDataSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -59,33 +59,33 @@ - (instancetype)initWithQuery:(FIRDatabaseQuery *)query

#pragma mark - FUICollectionDelegate methods

- (void)array:(FUIArray *)array didAddObject:(id)object atIndex:(NSUInteger)index {
- (void)arrayDidBeginUpdates:(id<FUICollection>)collection {
[self.tableView beginUpdates];
}

- (void)arrayDidEndUpdates:(id<FUICollection>)collection {
[self.tableView endUpdates];
}

- (void)array:(FUIArray *)array didAddObject:(id)object atIndex:(NSUInteger)index {
[self.tableView insertRowsAtIndexPaths:@[ [NSIndexPath indexPathForRow:index inSection:0] ]
withRowAnimation:UITableViewRowAnimationAutomatic];
[self.tableView endUpdates];
}

- (void)array:(FUIArray *)array didChangeObject:(id)object atIndex:(NSUInteger)index {
[self.tableView beginUpdates];
[self.tableView reloadRowsAtIndexPaths:@[ [NSIndexPath indexPathForRow:index inSection:0] ]
withRowAnimation:UITableViewRowAnimationAutomatic];
[self.tableView endUpdates];
}

- (void)array:(FUIArray *)array didRemoveObject:(id)object atIndex:(NSUInteger)index {
[self.tableView beginUpdates];
[self.tableView deleteRowsAtIndexPaths:@[ [NSIndexPath indexPathForRow:index inSection:0] ]
withRowAnimation:UITableViewRowAnimationAutomatic];
[self.tableView endUpdates];
}

- (void)array:(FUIArray *)array didMoveObject:(id)object
fromIndex:(NSUInteger)fromIndex toIndex:(NSUInteger)toIndex {
[self.tableView beginUpdates];
[self.tableView moveRowAtIndexPath:[NSIndexPath indexPathForRow:fromIndex inSection:0]
toIndexPath:[NSIndexPath indexPathForRow:toIndex inSection:0]];
[self.tableView endUpdates];
}

#pragma mark - UITableViewDataSource methods
Expand Down

0 comments on commit c51dec1

Please sign in to comment.