I have a UITableView that has five static cells. I need the cell height of one cell to adjust automatically to its contents, which is one UILabel.
Is there any way I
In IOS8, I've found that explicitly setting the row height/width or label height/width in code causes more problems than it fixes. I have created dynamic and static tables with varying cell height and multiline labels using autolayout, but you really have to follow Apple standard to the letter or weird things happen (like separators disappearing or rows randomly collapsing in height).
[edited] Set estimatedHeightForRowAtIndexPath and heightForRowAtIndexPath to automatic dimensions in your UITableViewDelegate
override func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
Make sure every single element in the cell has a top/bottom/left/right = constraint (not >=, <=, or alignX or alignY - it has to be =). You can make this a low priority constraint and provide a better constraint of higher priority, but you have to give it an exact starting value to size the cell.