2014-04-16 84 views
0

我有一個自定義單元格的tableview,裏面有一個textview。 對於這個單元格,我用文本的大小確定它的高度,這沒關係。iOS:自定義tableview單元格中的約束

我在自動佈局工作,所以我的手機我用兩個約束條件,擴大爲所有空間細胞TextView的這樣

enter image description here

我可以說,它做工精細,我的TextView的擴大本身所有單元格空間。

在視圖控制器中,我有一個控件來檢查文本(字符串)是否爲空。當它爲空時,我爲cell Hight返回0。

但在這種情況下,當我返回0和text_view爲空我有一個崩潰,但我不知道如何解決。

這是消息

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:0x1704864a0 V:|-(25)-[UITextView:0x15454d960] (Names: '|':UITableViewCellContentView:0x178179680)>", 
    "<NSLayoutConstraint:0x1704864f0 V:[UITextView:0x15454d960]-(23)-| (Names: '|':UITableViewCellContentView:0x178179680)>", 
    "<NSAutoresizingMaskLayoutConstraint:0x17889a220 h=--& v=--& V:[UITableViewCellContentView:0x178179680(0)]>" 
) 

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x1704864f0 V:[UITextView:0x15454d960]-(23)-| (Names: '|':UITableViewCellContentView:0x178179680)> 

Break on objc_exception_throw to catch this in the debugger. 
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful. 
+1

你爲什麼包括如果沒有內容的行? – Wain

+1

嘗試設置'[self.contentView setTranslatesAutoresizingMaskIntoConstraints:NO];'在自定義單元格中。 – Akhilrajtr

+0

將視圖的alpha設置爲0是隱藏視圖的好方法。 – BoranA

回答

1

設置TranslatesAutoresizingMaskIntoConstraints由細胞內容查看的NO

[self.contentView setTranslatesAutoresizingMaskIntoConstraints:NO]; 
相關問題