我想设置动态基于详细文本标签设置的内容行的高度,通过使用部分A.下面的代码的iOS斯威夫特动态调整的tableview单元格的高度根据内容 -
我将几行文本插入到单元格的详细文本标签中,如下面的B部分所示:
我已经查看了其他类似的问题,但都没有帮助。
有人可以请教我如何根据详细文本标签的内容动态调整行高度。
A部分
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
也试过
func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
B部分
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "daysIdentifier", for: indexPath)
cell.textLabel?.text = days[indexPath.row]
cell.detailTextLabel?.numberOfLines = 0
var joinedString = self.availabilityTimeDict[dayName]?.joined(separator: " \n ")
cell.detailTextLabel?.text = joinedString
return cell
}
设置标签的顶部和底部限制正确,也设置tableView.estimateRowHeight = 50 –