我有一个非常简单的UITableViewController,在这里我想设置一个文本上的每个textLabel中的UITableViewCell秒.
高度应通过autolayout计算.因此,在我viewDidLoad的tableView属性中设置以下值:
tableView.estimatedRowHeight = UITableViewAutomaticDimension
tableView.rowHeight = UITableViewAutomaticDimension
Run Code Online (Sandbox Code Playgroud)
这是我的cellForRow方法,我初始化默认值UITableViewCell并将文本设置为其标签.
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell()
cell.textLabel?.numberOfLines = 0
cell.textLabel?.text = "hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello"
return cell
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,细胞不会根据标签的大小而增长.此问题仅出现在iOS 10上.在iOS 11上,所有内容都应该布局.
请检查以下屏幕截图:
编辑:2018年5月24日
拥有textLabel …