From 07afcd6f36629f30a495f2be47262c75c006712f Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Mon, 16 Oct 2017 19:02:41 +0300 Subject: begin updates --- Juick/ViewControllers/MessagesViewController.m | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Juick/ViewControllers/MessagesViewController.m b/Juick/ViewControllers/MessagesViewController.m index badc4a3..e4d0e1c 100644 --- a/Juick/ViewControllers/MessagesViewController.m +++ b/Juick/ViewControllers/MessagesViewController.m @@ -32,10 +32,10 @@ self.dataLoading = YES; [[APIClient sharedClient] pullNextFromPath:self.path params:self.params callback:^(NSArray *next, NSError *err) { NSArray *newMsgs = next; + NSUInteger oldCount = [self.messages count]; if ([self.path isEqualToString:[APIClient threadUrl]]) { NSUInteger lastRid = [((Message *)[self.messages lastObject]).rid unsignedIntegerValue]; NSUInteger count = [next count] - 1; - NSUInteger oldCount = [self.messages count]; if (oldCount > 0) { if (lastRid && lastRid < count) { newMsgs = [next subarrayWithRange:NSMakeRange(lastRid, count - lastRid)]; @@ -45,7 +45,13 @@ } } [self.messages addObjectsFromArray:newMsgs]; - [self.tableView reloadData]; + NSMutableArray *indexPaths = [NSMutableArray new]; + for (NSUInteger index = oldCount; index <= oldCount + [newMsgs count] - 1; index++) { + [indexPaths addObject:[NSIndexPath indexPathForRow:index inSection: 0]]; + } + [self.tableView beginUpdates]; + [self.tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:YES]; + [self.tableView endUpdates]; [self.refreshControl endRefreshing]; self.dataLoading = NO; }]; @@ -114,10 +120,10 @@ [self.navigationController pushViewController:threadViewController animated:NO]; } --(void)scrollViewDidScroll:(UIScrollView *)scrollView_ { +-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView_ { CGFloat actualPosition = scrollView_.contentOffset.y; CGFloat contentHeight = scrollView_.contentSize.height - scrollView_.contentSize.height / 2; - if (actualPosition >= contentHeight && !self.dataLoading) { + if (actualPosition >= contentHeight && !self.dataLoading && ![self.tableView isTracking]) { Message *lastMsg = [self.messages lastObject]; if (lastMsg != nil) { NSNumber *lastMid = lastMsg.mid; -- cgit v1.2.3