Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- - (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject
- atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type
- newIndexPath:(NSIndexPath *)newIndexPath
- {
- switch(type) {
- case NSFetchedResultsChangeInsert:
- [_insertions addObject:@(newIndexPath.row)];
- break;
- }
- }
- - (void)controllerWillChangeContent:(NSFetchedResultsController *)controller {
- _insertions = @[].mutableCopy;
- }
- - (void)controllerDidChangeContent:(NSFetchedResultsController *)controller {
- NSMutableArray *copy = _insertions.mutableCopy;
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- NSSortDescriptor *lowestToHighest = [NSSortDescriptor sortDescriptorWithKey:@"self" ascending:YES];
- [copy sortUsingDescriptors:[NSArray arrayWithObject:lowestToHighest]];
- dispatch_sync(dispatch_get_main_queue(), ^{
- for (NSNumber *i in copy) {
- [self p_delayedAddRowAtIndex:[i integerValue]];
- }
- [self.tableView reloadData];
- });
- });
- }
- - (CGFloat)p_firstRowHeight {
- return [self tableView:[self tableView] heightForRowAtIndexPath:[NSIndexPath indexPathForRow:0
- inSection:0]];
- }
- -(void)p_delayedAddRowAtIndex:(NSInteger)row {
- NSIndexPath *firstVisibleIndexPath = [[self.tableView indexPathsForVisibleRows] firstObject];
- if (firstVisibleIndexPath.row >= row) {
- CGPoint offset = [[self tableView] contentOffset];
- offset.y += [self firstRowHeight];
- if ([self.tableView visibleCells].count > self.tableView.frame.size.height / [self firstRowHeight]) {
- [[self tableView] setContentOffset:offset];
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement