summaryrefslogtreecommitdiff
path: root/Juick/MessagesViewController.m
diff options
context:
space:
mode:
Diffstat (limited to 'Juick/MessagesViewController.m')
-rw-r--r--Juick/MessagesViewController.m37
1 files changed, 23 insertions, 14 deletions
diff --git a/Juick/MessagesViewController.m b/Juick/MessagesViewController.m
index 4518686..64d7106 100644
--- a/Juick/MessagesViewController.m
+++ b/Juick/MessagesViewController.m
@@ -27,6 +27,7 @@ static NSString *CellIdentifier = @"MessageCell";
@property(nonatomic, assign) Boolean dataLoading;
@property(nonatomic, strong) NSString *path;
@property(nonatomic, strong) NSMutableDictionary *params;
+@property(nonatomic, strong) MessageCell *sizingCell;
@end
@@ -43,11 +44,17 @@ static NSString *CellIdentifier = @"MessageCell";
- (void) refreshData:(UIRefreshControl *)refresh {
[self.messages removeAllObjects];
[self.tableView reloadData];
- [Message pullNextFromPath:self.path params:self.params callback:^(NSArray *next) {
- [self.messages addObjectsFromArray:next];
- [self.tableView reloadData];
- [refresh endRefreshing];
- }];
+ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+ self.dataLoading = YES;
+ [Message pullNextFromPath:self.path params:self.params callback:^(NSArray *next) {
+ dispatch_async(dispatch_get_main_queue(), ^{
+ [self.messages addObjectsFromArray:next];
+ [self.tableView reloadData];
+ [refresh endRefreshing];
+ self.dataLoading = NO;
+ });
+ }];
+ });
}
- (UIStatusBarStyle)preferredStatusBarStyle
@@ -103,6 +110,11 @@ static NSString *CellIdentifier = @"MessageCell";
}
[self.tableView registerClass:[MessageCell class] forCellReuseIdentifier:CellIdentifier];
+ self.sizingCell = [[MessageCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
+ self.sizingCell.hidden = YES;
+ [self.tableView addSubview:self.sizingCell];
+
+ self.sizingCell.frame = CGRectMake(0, 0, CGRectGetWidth(self.tableView.bounds), 0);
}
- (void) composePressed {
@@ -161,27 +173,24 @@ static NSString *CellIdentifier = @"MessageCell";
Message *msg = [_messages objectAtIndex:indexPath.row];
[cell bind:msg];
- cell.bodyLabel.preferredMaxLayoutWidth = CGRectGetWidth(cell.bodyLabel.frame);
[cell.contentView layoutIfNeeded];
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
- MessageCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
-
- [cell updateFonts];
+ [self.sizingCell updateFonts];
Message *msg = [_messages objectAtIndex:indexPath.row];
- [cell bind:msg];
+ [self.sizingCell bind:msg];
- cell.bodyLabel.preferredMaxLayoutWidth = CGRectGetWidth(cell.bodyLabel.frame);
- [cell.contentView layoutIfNeeded];
+ [self.sizingCell setNeedsLayout];
+ [self.sizingCell layoutIfNeeded];
- CGFloat height = [cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
+ CGFloat calculatedHeight = [self.sizingCell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
- return height;
+ return calculatedHeight;
}
- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath