title: AMBIGUOUS LAYOUT for view Height
body: <p>I have an <code>UITableView</code> with a cell which contains:</p>
  
  <p><code>Title label + UIStackView</code> with some buttons and below it an <code>UIStackView</code> with another label (description), <code>UICollectionView</code> (set of images) and a button. Title label is pinned to leading, trailing and top superview and bottom to the <code>UIStackView</code> (which is pinned to leading, trailing, bottom of label and bottom of the superview).</p>
  
  <p><a href="https://i.stack.imgur.com/VXl8Y.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VXl8Y.png" alt="enter image description here"></a></p>
  
  <p>I'm also using <code>UITableViewAutomaticDimension</code> and that's because content height might be different inside <code>UIStackView</code> (images, text).</p>
  
  <p>Before I've added an <code>UICollectionView</code> to the <code>UIStackView</code> everything worked fine, but after adding it on some occasions layout brokes (everything inside <code>UIStackView</code> is overlapped) and in View UI Hierarchy I can see warnings:</p>
  
  <p><a href="https://i.stack.imgur.com/ANOSx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ANOSx.png" alt="enter image description here"></a></p>
  
  <pre><code>*UIView:0x1038635e0- AMBIGUOUS LAYOUT for UIView:0x1038635e0.Height{id: 3153}
  
  Legend:
      * - is laid out with auto layout
      + - is laid out manually, but is represented in the layout engine because translatesAutoresizingMaskIntoConstraints = YES
      • - layout engine host
  2018-01-03 10:19:58.527094+0100 Crowd Knowledge[1462:1408352] [LayoutConstraints] View has an ambiguous layout. See "Auto Layout Guide: Ambiguous Layouts" for help debugging. Displaying synopsis from invoking -[UIView _autolayoutTrace] to provide additional detail.
  
  *Crowd_Knowledge.AttachmentsCollectionView:0x104072e00- AMBIGUOUS LAYOUT for Crowd_Knowledge.AttachmentsCollectionView:0x104072e00.minY{id: 3263}, Crowd_Knowledge.AttachmentsCollectionView:0x104072e00.Height{id: 3252}
  
  Legend:
      * - is laid out with auto layout
      + - is laid out manually, but is represented in the layout engine because translatesAutoresizingMaskIntoConstraints = YES
      • - layout engine host
  2018-01-03 10:19:58.531696+0100 Crowd Knowledge[1462:1408352] [LayoutConstraints] View has an ambiguous layout. See "Auto Layout Guide: Ambiguous Layouts" for help debugging. Displaying synopsis from invoking -[UIView _autolayoutTrace] to provide additional detail.
  
  *UIButton:0x103854dc0'Edit solution'- AMBIGUOUS LAYOUT for UIButton:0x103854dc0'Edit solution'.minY{id: 3261}, UIButton:0x103854dc0'Edit solution'.Height{id: 3258}
  
  Legend:
      * - is laid out with auto layout
      + - is laid out manually, but is represented in the layout engine because translatesAutoresizingMaskIntoConstraints = YES
      • - layout engine host
  2018-01-03 10:19:59.247887+0100 Crowd Knowledge[1462:1408352] [LayoutConstraints] Window has a view with an ambiguous layout. See "Auto Layout Guide: Ambiguous Layouts" for help debugging. Displaying synopsis from invoking -[UIView _autolayoutTrace] to provide additional detail.
  
  *UIView:0x1038635e0- AMBIGUOUS LAYOUT for UIView:0x1038635e0.Height{id: 3153}
  
  Legend:
      * - is laid out with auto layout
      + - is laid out manually, but is represented in the layout engine because translatesAutoresizingMaskIntoConstraints = YES
      • - layout engine host
  </code></pre>
  
  <p>Also, my <code>UICollectionView</code> have a layout, which sets height based on content:</p>
  
  <pre><code>class DynamicCollectionView: UICollectionView {
  
      override func layoutSubviews() {
          super.layoutSubviews()
          if !__CGSizeEqualToSize(bounds.size, self.intrinsicContentSize) {
              self.invalidateIntrinsicContentSize()
          }
      }
  
      override var intrinsicContentSize: CGSize {
          return contentSize
      }
  
  }
  </code></pre>
  
  <p>I don't have any warnings in storyboard and it works 90% of the time. If it's broken all I have to do is to scroll the other cell so it'll refresh and constraints are working again. I've tried various tricks to force updating the UI <code>(tableView.beginUpdates() + tableView.endUpdates())</code>, but still I cannot find a solution which works always.</p>
  
  <p>I'm looking for a clean solution for this problem.</p>