diff options
Diffstat (limited to 'Juick/MessagesViewController.m')
-rw-r--r-- | Juick/MessagesViewController.m | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/Juick/MessagesViewController.m b/Juick/MessagesViewController.m index 2cf4267..25622a9 100644 --- a/Juick/MessagesViewController.m +++ b/Juick/MessagesViewController.m @@ -39,14 +39,8 @@ static NSString *CellIdentifier = @"MessageCell"; [self setParams:[[NSMutableDictionary alloc] initWithDictionary:params]]; self.title = title; __weak MessagesViewController * weakSelf = self; - [self.tableView addPullToRefreshWithActionHandler:^{ - [weakSelf.messages removeAllObjects]; - [weakSelf refreshData]; - }]; - [self.tableView addInfiniteScrollingWithActionHandler:^{ - [weakSelf refreshData]; - }]; - [self.tableView triggerPullToRefresh]; + [self.messages removeAllObjects]; + [weakSelf refreshData]; } - (void) refreshData { @@ -55,6 +49,7 @@ static NSString *CellIdentifier = @"MessageCell"; [Message pullNextFromPath:self.path params:self.params callback:^(NSArray *next) { [self.messages addObjectsFromArray:next]; [self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO]; + [self.refreshControl performSelectorOnMainThread:@selector(endRefreshing) withObject:nil waitUntilDone:NO]; self.dataLoading = NO; }]; }); @@ -84,6 +79,15 @@ static NSString *CellIdentifier = @"MessageCell"; [self.tableView registerNib:[UINib nibWithNibName:@"MessageCell" bundle:nil] forCellReuseIdentifier:CellIdentifier]; self.tableView.rowHeight = UITableViewAutomaticDimension; self.tableView.estimatedRowHeight = 500.0f; + self.refreshControl = [UIRefreshControl new]; + [self.refreshControl addTarget:self action:@selector(refreshData) forControlEvents:UIControlEventValueChanged]; + __weak MessagesViewController * weakSelf = self; + [self.tableView addInfiniteScrollWithHandler:^(UITableView * _Nonnull tableView) { + NSNumber *lastMid = ((Message *)[weakSelf.messages lastObject]).MID; + [weakSelf.params setValue:lastMid forKey:@"before_mid"]; + [weakSelf refreshData]; + [weakSelf.tableView finishInfiniteScroll]; + }]; } - (void) composePressed { |