0
我需要你的幫助,因爲我不明白我的汽車約束會發生什麼。我的開關的限制使應用程序崩潰。當我刪除它,它很好地工作。 這是我得到的錯誤消息: 無法解釋'|'字符,因爲相關視圖沒有超視圖 H:| -100- [v0(35)] |無法解釋'|'字符
THX對您有所幫助
這裏是我的代碼:
class selectionCustomCell: UITableViewCell{
var label: UILabel = {
let attribution = UILabel()
attribution.text = "Nom du label"
attribution.textColor = UIColor(r: 0, g: 185, b: 255)
attribution.lineBreakMode = NSLineBreakMode.ByWordWrapping
attribution.numberOfLines = 0
attribution.translatesAutoresizingMaskIntoConstraints = false
return attribution
}()
var switchElement: UISwitch{
let sL = UISwitch()
sL.setOn(true, animated: true)
sL.onTintColor = UIColor(r: 0, g: 185, b: 255)
sL.tintColor = UIColor(r: 0, g: 185, b: 255)
sL.translatesAutoresizingMaskIntoConstraints = false
return sL
}
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: .Default, reuseIdentifier: reuseIdentifier)
addSubview(switchElement)
addSubview(label)
setupViews()
}
func setupViews(){
addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|-20-[v0]|", options: NSLayoutFormatOptions(), metrics: nil, views: ["v0": label]))
addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-20-[v0]", options: NSLayoutFormatOptions(), metrics: nil, views: ["v0": label]))
addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|-100-[v0(35)]|", options: NSLayoutFormatOptions(), metrics: nil, views: ["v0": switchElement]))
addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-20-[v0(35)]", options: NSLayoutFormatOptions(), metrics: nil, views: ["v0": switchElement]))
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
THX你了。有用 !!!我正在拉我的頭髮 –