I have an UITableView
with a cell which contains:
Title label + UIStackView
with some buttons and below it an UIStackView
with another label (description), UICollectionView
(set of images) and a button. Title label is pinned to leading, trailing and top superview and bottom to the UIStackView
(which is pinned to leading, trailing, bottom of label and bottom of the superview).
I'm also using UITableViewAutomaticDimension
and that's because content height might be different inside UIStackView
(images, text).
Before I've added an UICollectionView
to the UIStackView
everything worked fine, but after adding it on some occasions layout brokes (everything inside UIStackView
is overlapped) and in View UI Hierarchy I can see warnings:
*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
Also, my UICollectionView
have a layout, which sets height based on content:
class DynamicCollectionView: UICollectionView {
override func layoutSubviews() {
super.layoutSubviews()
if !__CGSizeEqualToSize(bounds.size, self.intrinsicContentSize) {
self.invalidateIntrinsicContentSize()
}
}
override var intrinsicContentSize: CGSize {
return contentSize
}
}
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 (tableView.beginUpdates() + tableView.endUpdates())
, but still I cannot find a solution which works always.
I'm looking for a clean solution for this problem.