无法满足TableViewCell中的约束

时间:2015-05-07 10:26:50

标签: ios uitableview swift nslayoutconstraint tableviewcell

我有一个带有this原型的TableViewCell。

当用户选择"否"在分段控件中,应显示用于注释的textView。我创建了一个QuestionTableViewCell类:

class QuestionTableViewCell: UITableViewCell {

    @IBOutlet weak var question: UILabel!
    @IBOutlet weak var answer: UISegmentedControl!
    @IBOutlet weak var comment: UITextView!
    // height constraint for comment textView
    @IBOutlet weak var heightConstraint: NSLayoutConstraint!
    // spacing between segmentedControl bottom and comment textView top
    @IBOutlet weak var spacingConstraint: NSLayoutConstraint!
}

然后在cellForRowAtIndexPath中设置此约束以满足我的需要:

if questionsAnswers[indexPath.row] == "" || questionsAnswers[indexPath.row] == "YES" {
    comments[indexPath.row] = ""
    cell.heightConstraint.constant = 0.0
    cell.spacingConstraint.constant = 0.0
} else {
    cell.spacingConstraint.constant = 8
    cell.heightConstraint.constant = 70.0
}

但是当我点击"否"在单元格的textView中我得到了这些约束碰撞:

"<NSLayoutConstraint:0x7fa28311d030 V:[UITextView:0x7fa2818c1600'Add a note if necessary..'(70)]>",
"<NSLayoutConstraint:0x7fa283123930 UILabel:0x7fa283119f20'1. Question 1?'.top == UITableViewCellContentView:0x7fa283119de0.topMargin>",
"<NSLayoutConstraint:0x7fa283123a20 V:[UILabel:0x7fa283119f20'1. Question 1?']-(NSSpace(8))-[UISegmentedControl:0x7fa28311a8d0]>",
"<NSLayoutConstraint:0x7fa283123bd0 UITextView:0x7fa2818c1600'Add a note if necessary..'.bottom == UITableViewCellContentView:0x7fa283119de0.bottomMargin>",
"<NSLayoutConstraint:0x7fa283123c20 V:[UISegmentedControl:0x7fa28311a8d0]-(8)-[UITextView:0x7fa2818c1600'Add a note if necessary..']>",
"<NSLayoutConstraint:0x7fa280cb4e30 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x7fa283119de0(73.5)]>"

我认为这种约束打破了布局:

"<NSLayoutConstraint:0x7fa280cb4e30 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x7fa283119de0(73.5)]>"

但我不知道如何解决这个问题(任何想法如何解决?

0 个答案:

没有答案