KJ3*_*KJ3 2 uitableview ios swift
我在UITableView中使用了字幕单元格.我已设置以下内容viewDidLoad以使行高自动扩展:
tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = 100
Run Code Online (Sandbox Code Playgroud)
我还将单元格的标题和副标题设置为自动换行:
cell.textLabel?.numberOfLines = 0
cell.textLabel?.lineBreakMode = .byWordWrapping
cell.detailTextLabel?.numberOfLines = 0
cell.detailTextLabel?.lineBreakMode = .byWordWrapping
Run Code Online (Sandbox Code Playgroud)
当我输入标题时,一切都很好.但副标题并没有扩大排.还有什么我需要做的才能让字幕增加行高吗?

之后,编写tableview的这两个委托方法.
func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
Run Code Online (Sandbox Code Playgroud)
因此,tableview高度按照文本大小增加.