iOS:自定义tableview单元格中的约束

时间:2014-04-16 11:32:00

标签: ios uitableview uitextview constraints autolayout

我有一个自定义单元格的tableview,其中有一个textview。 对于这个单元格,我用文本的大小确定它的高度,这没关系。

我在autolayout工作,所以对于我的单元格,我使用两个约束以这种方式扩展所有空间单元格的textview

enter image description here

我可以说它工作正常,我的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.

1 个答案:

答案 0 :(得分:1)

TranslatesAutoresizingMaskIntoConstraints设置为单元格contentView的NO

[self.contentView setTranslatesAutoresizingMaskIntoConstraints:NO];