Ios uitableviewcell内的imageview折叠单元格
这是带有图像视图的选项卡视图单元格Ios uitableviewcell内的imageview折叠单元格,ios,swift,uitableview,ios-autolayout,Ios,Swift,Uitableview,Ios Autolayout,这是带有图像视图的选项卡视图单元格 class ChatTableViewCell: UITableViewCell { override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { super.init(style: style, reuseIdentifier: reuseIdentifier) self.contentView.addSubview(use
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
}
这就是控制台中显示的错误
[警告]仅警告一次:检测到约束模糊地表示表视图单元格内容视图的高度为零的情况。我们正在考虑非故意的坍塌,并使用标准高度代替。单元格:>您可以使用
contentView
,严格来说这不是必需的,我使用的是strightself.addSubview()
因为图像的高度大于标准行的高度。如果高度大于
55
,则必须使用UITableViewDelegate
方法heightForRow
实现高度,或者添加底部锚定:userImageView.bottomAnchor.constraint(equalTo:self.bottomAnchor).isActive=true
将底部约束从图像视图的底部添加到内容视图的底部锚点。如果需要,您可以将其设置为低优先级,以允许其他内容影响刚打破my imageview约束的高度。将尝试通过打破约束进行恢复。如果topconstraint的高度不足以让tableview单元格计算高度,则需要解决内容视图,因此,您需要从顶部到底部的约束,从这一点可以计算出总体高度,但它仍然打破了约束