简体   繁体   English

为什么tableView单元格不动态?

[英]Why is tableView cell not dynamic?

Update: 更新:

I have found that the problem occurs because of the date labels top constraint when removed the wrapped text becomes visible. 我发现问题的发生是因为日期标签顶部约束时删除包装文本变得可见。 The issue is then the date label is under the other text. 问题是日期标签在其他文本下面。 Could the real problem be that the cell is not dynamically changing based on the constraints? 真正的问题可能是细胞没有根据约束动态变化吗?

I am trying to make text in a UILabel to wrap (at the same time I am trying to make the cell change based on the text) 我试图在UILabel中包装文本(同时我试图根据文本更改单元格)

In the .xib I setup the cell, doing this: .xib我设置了单元格,这样做:

    self.notifInfoLabel.numberOfLines = 0
    self.notifInfoLabel.lineBreakMode = .byWordWrapping

在此输入图像描述 sizeToFit is called right before returning the cell in the delegate method. 在委托方法中返回单元格之前调用sizeToFit

cell.notifInfoLabel.sizeToFit()//EDIT: turns out this is not needed

    return cell
}

The configure method is called on viewDidLoad and right before .reloadData() configure方法在viewDidLoad上调用,就在.reloadData()之前.reloadData()

func configureTableView() {
    self.tableView.estimatedRowHeight = 82
    self.tableView.rowHeight = UITableView.automaticDimension
}

Currently, the text in the label seems to wrap underneath the date label... 目前,标签中的文字似乎包含在日期标签下面......

How can I make it work as intended? 如何让它按预期工作?

You have confusing constraints for Auto layout engine. 您有自动布局引擎的令人困惑的约束。

  • You want some space from bottom of image view if text is small , And 如果文字较小,你需要从图像视图底部留出一些空间

  • you want text to dynamic in that case label should grow. 你希望文本在这种情况下是动态的,标签应该增长。

Solution is very simple. 解决方案非常简单。

Bottom constraint of Imageview change = to >= with 750 priority Imageview底部约束变为= > = = 750优先级

Bottom constraint of Date change = to >= Date更改的底部约束= to > =

Hope it is helpful 希望它有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM