简体   繁体   English

iOS:限制在自定义表格视图单元格中

[英]iOS: Constraint in a custom tableview cell

I have a tableview with a custom cell, where inside it I have a textview. 我有一个带有自定义单元格的tableview,在其中有一个textview。 For this cell I determinate its hight with the size of text and it's ok. 对于此单元格,我用文本大小确定其高度,这没关系。

I work in autolayout, so for my cell I use two constraints to expand the textview for all space cell in this way 我在自动布局中工作,因此对于我的单元格,我使用两个约束以这种方式扩展所有空间单元格的textview

在此处输入图片说明

I can say that it work fine and my textview expand itself for all cell space. 我可以说它可以正常工作,并且我的textview可以针对所有单元格空间进行扩展。

In the view controller I have a control to check when the text (the string) is empty. 在视图控制器中,我有一个控件来检查文本(字符串)何时为空。 When it is empty I return 0 for the cell hight. 当它为空时,我为单元格高度返回0。

But in this case when I return 0 and text_view is empty I have a crash but I don't know how to solve. 但是在这种情况下,当我返回0且text_view为空时,我崩溃了,但我不知道如何解决。

this is the message 这是消息

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