Reputation: 2281
A picture tells a thousand words, so here's the image of my UITableViewCell with my constraints.
I have a view pinned to all edges of the content view, and inside there's another view with a fixed width and height, pinned to the bottom and top of the superview. I am trying to center the x axis of this view to its superview. Running on a device everything looks okay, but interface builder is throwing an error on the outer view, saying it needs constraints for Y position or height. Can I somehow bypass that in interface builder? Or am I missing something fundamental about self-sizing table cells?
I am sizing my table cells with:
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
Upvotes: 0
Views: 231
Reputation: 4437
Don't worry. You have done everything right. The warning is about the ambiguity raised due to two different heights of the tableViewCell.
Just change the cell height to 21( or 20 if your table view has no separators). The ambiguity would be resolved.
Note : Its 21, because the cell height is 1 + the height of the cell content view. This 1 point is for the separator line.
Also even if you don't do any changes the UI will be fine as this ambiguity would be solved at run time where height is calculated fro the content. Hence height fed in the IB is overridden by the calculated height, hence no issues.
Upvotes: 1