Skip to content

Instantly share code, notes, and snippets.

@iosappdeveloper
Created August 14, 2014 16:01
Show Gist options
  • Save iosappdeveloper/c040224c4861aef1641d to your computer and use it in GitHub Desktop.
Save iosappdeveloper/c040224c4861aef1641d to your computer and use it in GitHub Desktop.
Dynamic table view cell height using auto layout
// $$$ Not self tested yet but accepted answer at http://stackoverflow.com/questions/25306299/how-to-make-autosizeheight-uitableviewcell
// For iOS 6 and 7. After iOS 8, it's claimed to be automatic.
@property (nonatomic, strong) CustomCell *layoutTableViewCell;
UINib *cellNib = [UINib nibWithNibName:CustomCellNibName bundle:nil];
self.layoutTableViewCell = [[cellNib instantiateWithOwner:nil options:nil] objectAtIndex:0];
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
CustomCell *cell = self.layoutTableViewCell;
[cell configureWithText:text];
CGSize layoutSize = [cell systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];
return layoutSize.height;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment