2015-01-21 59 views
2

我有一個UITableView,其內容有些動態。似乎每次我調整他們的時候,我打這個錯誤:如何判斷UITableView自身尺寸的高度即將改變?

Unable to simultaneously satisfy constraints. 

    Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 

(

    "<NSLayoutConstraint:0x15dbabf0 WKWebView:0x15da1650.top == UITableViewCellContentView:0x15eaedb0.topMargin>", 

    "<NSLayoutConstraint:0x15dbac20 UITableViewCellContentView:0x15eaedb0.bottomMargin == WKWebView:0x15da1650.bottom>", 

    "<NSLayoutConstraint:0x15db1360 V:[WKWebView:0x15da1650(158)]>", 

    "<NSLayoutConstraint:0x15ed0c00 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x15eaedb0(43.5)]>" 

) 

這是最後一個 - 的一個標記UIView-Encapsulated-Layout-Height - 那就是摔東西。我想擺脫它,或者把它設置成突破性的優先級,或者什麼 - 但我似乎無法告訴UITableView打破它。我已經在各種視圖上嘗試了各種可能的組合setNeedsUpdateConstraintssetNeedsLayout。我嘗試從updateConstraints上的單元格contentView中刪除所有約束條件。我試過只是打電話beginUpdatesendUpdates - 在這種情況下,updateConstraints永遠不會被稱爲&約束不重新評估。

我不知所措,在這裏。如果沒有自定義單元格,只需調用begin/endUpdates來觸發重新計算單元格的尺寸。我現在怎麼做?

+0

您需要根據需要正確設置單元格的約束條件,然後需要正確計算高度。 – TamilKing 2015-01-21 04:25:42

+0

@TamilKing我正在討論iOS 8中的自動調整表格視圖單元格。查看視頻以瞭解*什麼是表格和集合視圖中的新增內容*來自WWDC 2014. – 2015-01-21 04:30:26

+0

刪除單元格並將其添加回新合同 並給單元格高度HeightForRowAtIndexPath – Shoaib 2015-01-21 04:31:41

回答

0

您在內容視圖中使用的WKWebView是造成約束最可能的原因。此外,只有在WebView完成加載後才能計算任何webView的高度。例如,在UIWebView中,只能在delgate方法「didFinishLoadingWebView」方法中正確提取UIWebView的高度。

另外,'UIView-Encapsulated-Layout-Height'約束據說不會得到滿足,因爲計算的單元的內在高度可能有不同的值。因此,可以降低相關單元約束的優先級,以使UIView-Encapsulated-Layout-Height具有優先級。