From e76034045b49064329d6834862e8c78ab8525c91 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Fri, 20 Jul 2018 00:03:10 +0300 Subject: Pull-to-refresh fix --- Juick/APIClient.m | 1 + Juick/ViewControllers/MessagesViewController.m | 8 ++++++++ 2 files changed, 9 insertions(+) (limited to 'Juick') diff --git a/Juick/APIClient.m b/Juick/APIClient.m index 1b3fb6e..5c21f19 100644 --- a/Juick/APIClient.m +++ b/Juick/APIClient.m @@ -29,6 +29,7 @@ if (self = [super init]) { self.manager = [[AFHTTPSessionManager alloc] initWithBaseURL:[NSURL URLWithString:@"https://api.juick.com"]]; self.manager.requestSerializer = [AFJSONRequestSerializer new]; + [self.manager.requestSerializer setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData]; self.backgroundQueue = [NSOperationQueue new]; self.dateFormatter = [[NSDateFormatter alloc] init]; self.dateFormatter.dateFormat = @"yyyy-MM-dd HH:mm:ss"; diff --git a/Juick/ViewControllers/MessagesViewController.m b/Juick/ViewControllers/MessagesViewController.m index a37f502..957fce5 100644 --- a/Juick/ViewControllers/MessagesViewController.m +++ b/Juick/ViewControllers/MessagesViewController.m @@ -31,6 +31,10 @@ self.dataLoading = YES; [[APIClient sharedClient] pullNextFromPath:self.path params:self.params callback:^(NSArray *next, NSError *err) { NSArray *newMsgs = next; + if ([self isAtTop:self.params]) { + [self.messages removeAllObjects]; + [self.tableView reloadData]; + } NSUInteger oldCount = [self.messages count]; if ([self.path isEqualToString:[APIClient threadUrl]]) { NSUInteger lastRid = [((Message *)[self.messages lastObject]).rid unsignedIntegerValue] + 1; @@ -60,6 +64,10 @@ }]; } +-(BOOL) isAtTop:(NSDictionary *)params { + return [params objectForKey:@"before_mid"] == nil && [params objectForKey:@"to"] == nil; +} + - (UIStatusBarStyle)preferredStatusBarStyle { return UIStatusBarStyleLightContent; -- cgit v1.2.3