iOS uitableview constraint error when setting Tableheaderview uiview-encapsulated-layout-height uiview-encapsulated-layout-width

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.