gpt4 book ai didi

swift - 无法以编程方式设置 TableView 单元格 - 线程 1 : EXC_BAD_ACCESS (code=EXC_I386_GPFLT)

转载 作者:行者123 更新时间:2023-11-28 11:29:51 25 4
gpt4 key购买 nike

我正在尝试使用自动布局以编程方式设置我的 UITableView 单元格,但它一直崩溃,我不确定为什么会这样。请问有人可以建议吗?

我正在尝试使用自动布局以编程方式设置我的 UITableView 单元格,但它一直崩溃,我不确定为什么会这样。请问有人可以建议吗?

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
}

我遇到以下崩溃:

enter image description here

最佳答案

看起来您没有启动 aTitle 标签。在使用之前尝试启动它。

 var aTitle: UILabel = {
let label = UILabel()
label.font = UIFont.boldSystemFont(ofSize: 15)
label.textColor = UIColor.gray
return label
}()

关于swift - 无法以编程方式设置 TableView 单元格 - 线程 1 : EXC_BAD_ACCESS (code=EXC_I386_GPFLT),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57141848/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com