Created
August 14, 2014 16:01
-
-
Save iosappdeveloper/c040224c4861aef1641d to your computer and use it in GitHub Desktop.
Dynamic table view cell height using auto layout
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// $$$ 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