When you set the Tableheaderview of UITableView to the view I created myself,
When I start debugging after I add a constraint for this custom view,
then symbol Breakpoint uiviewalertforunsatisfiableconstraints hit,
The terminal output the following error message:
211.666666666667> "," <nslayoutconstraint:0x170682760 'uiview-encapsulated-layout-height 212 (Active) > "would attempt to recover by breaking constraint <nslayoutconstraint:0x170682760 ' Uiview-encapsulated-layout-height ' uiview:0x1017eb5e0.height = = 212 (Active) >
This is actually the CollectionView for your custom View automatically added additional constraints ,
However, the constraints it adds are the same as the precedence of the constraints you add .
So the key to solving the problem is to reduce the precedence of the constraints you set ;
Solutions Reference:
First, if you use the API provided by UIKit to set constraints, you can refer to the following OC code:
Nsarray * Collectionconstraints_v = [nslayoutconstraint constraintswithvisualformat:@ "V:|-0-[_collectionview]-0-|" options:0 Metrics:nil Views:viewsdic]; [Self addconstraints:collectionconstraints_v]; Nsarray * Collectionconstraints_h = [Nslayoutconstraint constraintswithvisualformat:@ "H:|-103-[_collectionview]" options:0 Metrics:nil Views:viewsdic]; [Self addconstraints:collectionconstraints_h]; Nslayoutconstraint * constraint = [Nslayoutconstraint constraintswithvisualformat:@ "h:[_collectionview]-0-|" options : 0 Metrics:nil views:viewsdic].firstobject;constraint.priority = uilayoutprioritydefaultlow; [Self addconstraint:constraint];
Second, if you use Snapkit to set constraints, you can refer to the following Swift code:
askContainer.snp.makeConstraints {(m) in M.top.equalto (detailTV.snp.top) M.leading.equalto ( detailTV.snp.leading) M.width.equalto (screen_width) let height = m.height.equalto (height). constraint Height.layoutConstraints.first?. Priority = Uilayoutprioritydefaultlow}
Reference: http://blog.csdn.net/hello_hwc/article/details/47129711
Reprint Please specify source:http://www.cnblogs.com/ficow/p/7250330.html
iOS uitableview constraint error when setting Tableheaderview uiview-encapsulated-layout-height uiview-encapsulated-layout-width