ios UITableView設定tableHeaderView時發生約束錯誤 UIView-Encapsulated-Layout-Height UIView-Encapsulated-Layout-Width

來源:互聯網
上載者:User

標籤:.net   資訊   uitable   uil   size   16px   api   ade   其他   

 

 

在將UITableView的tableHeaderView設定為我自己建立的View的時候,

當我為這個自訂View添加約束之後啟動調試,

然後符號斷點UIViewAlertForUnsatisfiableConstraints命中了,

終端輸出了如下的報錯資訊:

("<SnapKit.LayoutConstraint:[email protected]#120 UIView:0x1017eb5e0.height == 211.666666666667>","<NSLayoutConstraint:0x170682760 ‘UIView-Encapsulated-Layout-Height‘ UIView:0x1017eb5e0.height == 212 (active)>")Will attempt to recover by breaking constraint <NSLayoutConstraint:0x170682760 ‘UIView-Encapsulated-Layout-Height‘ UIView:0x1017eb5e0.height == 212 (active)>

  

 

這其實是CollectionView為你的自訂View自動添加了其他約束,

然而它添加的約束和你添加的約束的優先順序是相同的。

 

所以解決問題的關鍵就是將你設定的約束的優先順序降低;

 

 

 

解決方案參考:

 

一、如果你使用了UIKit提供的API來設定約束,可以參考如下OC代碼:

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];

  

 

二、如果你使用了SnapKit來設定約束,可以參考如下Swift代碼:

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}

  

 

 

參考資料:http://blog.csdn.net/hello_hwc/article/details/47129711

 

 

轉載請註明出處:http://www.cnblogs.com/ficow/p/7250330.html

ios UITableView設定tableHeaderView時發生約束錯誤 UIView-Encapsulated-Layout-Height UIView-Encapsulated-Layout-Width

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.