添加单元格视图约束的错误

时间:2016-10-18 03:38:33

标签: constraints swift3

我正在尝试为单元格中的一个视图添加约束。 这是我的代码:

let labelView = UIView()
let labelItem = UILabel()

labelItem.text = menuList[indexPath.row-1]
labelItem.textColor = UIColor.white
labelView.addSubview(labelItem)

cell.addSubview(labelView)
labelView.translatesAutoresizingMaskIntoConstraints = false

NSLayoutConstraint(item: labelView, attribute: NSLayoutAttribute.width, relatedBy: NSLayoutRelation.equal, toItem: cell, attribute: NSLayoutAttribute.notAnAttribute, multiplier: 1, constant: wCell).isActive = true
NSLayoutConstraint(item: labelView, attribute: NSLayoutAttribute.leading, relatedBy: NSLayoutRelation.equal, toItem: cell, attribute: NSLayoutAttribute.leadingMargin, multiplier: 1.0, constant: 10.0).isActive = true

但是,它错误" libc ++ abi.dylib:以NSException类型的未捕获异常终止"。你能帮助我吗?非常感谢

1 个答案:

答案 0 :(得分:0)

我相信以编程方式添加约束的方法已在Swift 3中更改,请在此处查看更多信息: https://developer.apple.com/library/content/documentation/UserExperience/Conceptual/AutolayoutPG/ProgrammaticallyCreatingConstraints.html