【发布时间】:2020-02-14 22:13:44
【问题描述】:
这是带有图像视图的表格视图单元格
class ChatTableViewCell: UITableViewCell {
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
self.contentView.addSubview(userImageView)
userImageView_constraints()
}
var userImageView: UIImageView = {
let imageView = UIImageView()
let imageViewHeightAndWidth: CGFloat = 55
let image = UIImage(named: "steve")
imageView.image = image
imageView.clipsToBounds = true
imageView.layer.cornerRadius = imageViewHeightAndWidth / 2
imageView.translatesAutoresizingMaskIntoConstraints = false
return imageView
}()
func userImageView_constraints(){
userImageView.leadingAnchor.constraint(equalTo: self.contentView.leadingAnchor, constant: 20).isActive = true
userImageView.topAnchor.constraint(equalTo: self.contentView.topAnchor, constant: 0).isActive = true
userImageView.widthAnchor.constraint(equalToConstant: 55).isActive=true
userImageView.heightAnchor.constraint(equalToConstant: 55).isActive=true
}
这是表格视图的代码
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "chatCell", for: indexPath) as! ChatTableViewCell
return cell
}
这是控制台中显示的错误
[警告] 仅警告一次:检测到约束模糊地建议表格视图单元格的内容视图高度为零的情况。我们正在考虑意外折叠并使用标准高度。单元格:>
【问题讨论】:
-
添加一个从图像视图底部到内容视图底部锚点的底部约束。如果需要,您可以将其设置为低优先级以允许其他内容影响高度
-
这只是打破了我的图像视图约束将尝试通过打破约束来恢复 <0x281e1a530 uiimageview:0x10132ca80.height="=">0x281e1a530>
标签: ios swift uitableview ios-autolayout