Contents
  1. 1. Make sure your static cell Autolayout is setup correctly
  2. 2. Dynamic height

In this post, I ‘ll show how to achieve varying row height with static tableview and autolayout

Make sure your static cell Autolayout is setup correctly

This step is the same as dynamic table view, just make sure you add constraints to the contentView, not the cell

Dynamic height

Since this is a static tableview, you don’t need that prototypeCell trick, you can just use the IBOutlet directly. This is what happens in my UITableViewDelegate, note how I reference descriptionLabel

[code language=”objc”]

  • (CGFloat)tableView:(UITableView )tableView heightForRowAtIndexPath:(NSIndexPath )indexPath
    {
    if (indexPath.section == 1 && indexPath.row > 0) {

    return 0;
    

    }

    if (indexPath.section == 0 && indexPath.row == 2) {

    CGSize size = [self.descriptionLabel systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];
    return size.height;
    

    }

    return [super tableView:tableView heightForRowAtIndexPath:indexPath];
    }
    [/code]

Note

Make you you have set preferredMaxLayoutWidth for the descriptionLabel

Reference

  1. Using Auto Layout in UITableView for dynamic cell layouts & variable row heights
  1. Dynamic Table View Cell Height and Auto Layout
  1. Table View Cells With Varying Row Heights
Contents
  1. 1. Make sure your static cell Autolayout is setup correctly
  2. 2. Dynamic height