From 5280123fef2cf2b64ed046ec6f76763ae6e4b455 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Thu, 30 Jan 2014 17:45:05 +0400 Subject: Sizing cell --- Juick/Juick-Info.plist | 4 ++-- Juick/MessagesViewController.m | 37 +++++++++++++++++++++++-------------- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/Juick/Juick-Info.plist b/Juick/Juick-Info.plist index 374a02f..f780290 100644 --- a/Juick/Juick-Info.plist +++ b/Juick/Juick-Info.plist @@ -17,11 +17,11 @@ CFBundlePackageType APPL CFBundleShortVersionString - 1.0.5 + 1.0.6 CFBundleSignature ???? CFBundleVersion - 1.0.5 + 1.0.6 LSApplicationCategoryType public.app-category.social-networking LSRequiresIPhoneOS 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 -- cgit v1.2.3