【发布时间】:2023-04-06 01:32:01
【问题描述】:
我需要根据消息标签文本更改单元格高度
对于消息标签,我已经给出了约束
trailing = leading = top = 10, height => 30 (greater then or equal to height)
和行数 = 0
现在标签在增加,但单元格没有增加,为什么?
o/p
代码:
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return msgArray.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "MessageDetailsTableViewCell", for: indexPath) as! MessageDetailsTableViewCell
self.tableView.separatorStyle = .none
cell.msgLabel.text = msgArray[indexPath.row]
cell.nameLabel.text = nameArray[indexPath.row]
cell.timeLabel.text = timeArray[indexPath.row]
cell.picImageview.image = UIImage(named: "icon12")
return cell
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 100//UITableView.automaticDimension
}
如果我给heightForRowAt = UITableView.automaticDimension 那么什么都没有,如果我将其高度固定为 100 则单元格不会增加,为什么?请帮忙
【问题讨论】:
-
请看这个appcoda.com/self-sizing-cells,希望对你有帮助。
-
检查你的单元格 lblheight 不会被修复。
-
您需要修复标签的底部布局约束
标签: ios swift uitableview label tableview