[英]Unable to setup UITableView cell programatically - thread 1: EXC_BAD_ACCESS (code=EXC_I386_GPFLT)
I am trying to setup my UITableView cell programmatically using auto layout but it keeps crashing and I am not sure why this is happening. 我正在尝试使用自动布局以编程方式设置UITableView单元,但是它一直崩溃,我不确定为什么会这样。 Please could someone advise?
有人可以请教吗?
I am trying to setup my UITableView cell programmatically using auto layout but it keeps crashing and I am not sure why this is happening. 我正在尝试使用自动布局以编程方式设置UITableView单元,但是它一直崩溃,我不确定为什么会这样。 Please could someone advise?
有人可以请教吗?
class FolderCell: UITableViewCell{
var jTitle: UILabel = {
let label = UILabel()
label.font = UIFont.italicSystemFont(ofSize: 12)
label.textColor = UIColor.gray
return label
}()
var date: UILabel = {
let label = UILabel()
label.font = UIFont.italicSystemFont(ofSize: 12)
label.textColor = UIColor.gray
return label
}()
var aTitle: UILabel {
let label = UILabel()
label.font = UIFont.boldSystemFont(ofSize: 15)
label.textColor = UIColor.gray
return label
}
var authors: UILabel = {
let label = UILabel()
label.font = UIFont.italicSystemFont(ofSize: 12)
label.textColor = UIColor.gray
return label
}()
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
cellSetup()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
private func cellSetup(){
contentView.addSubview(jTitle)
contentView.addSubview(aTitle)
contentView.addSubview(date)
contentView.addSubview(authors)
setUpLabels()
}
private func setUpLabels(){
jTitle.translatesAutoresizingMaskIntoConstraints = false
jTitle.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 10).isActive = true
jTitle.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 10).isActive = true
jTitle.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -10).isActive = true
aTitle.translatesAutoresizingMaskIntoConstraints = false
aTitle.topAnchor.constraint(equalTo: jTitle.bottomAnchor, constant: 10).isActive = true
aTitle.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 10).isActive = true
aTitle.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -10).isActive = true
}
} }
I am getting the following crash : 我遇到以下崩溃:
Looks like you didn't initiate the aTitle label. 好像您没有启动aTitle标签。 Try to initiate it before you use it.
使用它之前,请尝试将其初始化。
var aTitle: UILabel = {
let label = UILabel()
label.font = UIFont.boldSystemFont(ofSize: 15)
label.textColor = UIColor.gray
return label
}()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.