簡體   English   中英

iOS:限制在自定義表格視圖單元格中

[英]iOS: Constraint in a custom tableview cell

我有一個帶有自定義單元格的tableview,在其中有一個textview。 對於此單元格,我用文本大小確定其高度,這沒關系。

我在自動布局中工作,因此對於我的單元格,我使用兩個約束以這種方式擴展所有空間單元格的textview

在此處輸入圖片說明

我可以說它可以正常工作,並且我的textview可以針對所有單元格空間進行擴展。

在視圖控制器中,我有一個控件來檢查文本(字符串)何時為空。 當它為空時,我為單元格高度返回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.

將單元格contentView的TranslatesAutoresizingMaskIntoConstraints設置為NO

[self.contentView setTranslatesAutoresizingMaskIntoConstraints:NO];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM