diff options
author | Vitaly Takmazov | 2014-01-30 17:45:05 +0400 |
---|---|---|
committer | Vitaly Takmazov | 2014-01-30 17:45:05 +0400 |
commit | 5280123fef2cf2b64ed046ec6f76763ae6e4b455 (patch) | |
tree | 7d5daac255d1465f04d2f433114fae6ea17fb2d4 | |
parent | 63f9e9576991fa8e50ca728836c6ba6917bbbc26 (diff) |
Sizing cell
-rw-r--r-- | Juick/Juick-Info.plist | 4 | ||||
-rw-r--r-- | 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 @@ <key>CFBundlePackageType</key> <string>APPL</string> <key>CFBundleShortVersionString</key> - <string>1.0.5</string> + <string>1.0.6</string> <key>CFBundleSignature</key> <string>????</string> <key>CFBundleVersion</key> - <string>1.0.5</string> + <string>1.0.6</string> <key>LSApplicationCategoryType</key> <string>public.app-category.social-networking</string> <key>LSRequiresIPhoneOS</key> 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 |