xtrinch
xtrinch

Reputation: 2281

Interface builder constraint error

A picture tells a thousand words, so here's the image of my UITableViewCell with my constraints.

enter image description here

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

Answers (1)

BangOperator
BangOperator

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.

  1. Height 20 arising due to your constraints.
  2. Height provided (or default height i.e. 44) in the size inspector.

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.

enter image description here

Upvotes: 1

Related Questions