【发布时间】:2021-07-06 13:23:53
【问题描述】:
所以,我制作了一个带有自定义单元格(.xib 文件)的 UITableView,效果很好。问题是我现在想添加一个页脚,它需要一个 UIImageView 和一个 UILabel。
这就是我目前正在做的事情:(当然我在 viewDidLoad() 中执行这个函数)
private func setupTableViewFooter() {
/// Insight Logo
let myAppLogo = UIImageView()
myAppLogo.backgroundColor = .clear
myAppLogo.widthAnchor.constraint(equalToConstant: 110.0).isActive = true
myAppLogo.heightAnchor.constraint(equalToConstant: 60.0).isActive = true
myAppLogo.contentMode = .scaleAspectFit
myAppLogo.image = UIImage(named: "myAppLogo")
/// Description Label
let label = UILabel()
label.backgroundColor = .clear
label.widthAnchor.constraint(equalToConstant: self.view.frame.size.width - 60).isActive = true
label.heightAnchor.constraint(equalToConstant: 30.0).isActive = true
label.textAlignment = .left
label.textColor = K.Colors.black
label.font = UIFont(name: "Roboto-Medium", size: 13)
label.text = "Hello world!"
/// Stack View
let footer = UIStackView()
footer.axis = .vertical
footer.distribution = .fill
footer.alignment = .leading
footer.spacing = 00.0
footer.backgroundColor = .lightGray
footer.addArrangedSubview(myAppLogo)
footer.addArrangedSubview(label)
footer.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
footer.leftAnchor.constraint(equalTo: view.leftAnchor, constant: 30),
footer.rightAnchor.constraint(equalTo: view.rightAnchor, constant: -30),
footer.widthAnchor.constraint(equalTo: view.widthAnchor, constant: -60),
footer.heightAnchor.constraint(equalToConstant: 90)
])
self.tableView.tableFooterView = footer
}
我收到此错误:
libc++abi.dylib:以 NSException 类型的未捕获异常终止 *** 由于未捕获的异常“NSGenericException”而终止应用程序,原因:“无法使用锚点激活约束 <0x282fa0640><0x282f56400>0x282f56400>0x282fa0640>
标签: ios swift autolayout constraints