释放双眼,带上耳机,听听看~!
解决办法:
1>设置好模板单元格的自动布局
模板单元格中,subviews的自动局部必须要能够把单元格撑满。也就是说,iOS 必须能够通过内容的自动布局约束计算出 cell 的高。
根据cell的contentView中的各个子View计算出cell的正常高度,计算方式为:
cell 高度 = 第1个Label的top+第1个Label高度+第2个Label的top+第2个Label高度(根据内容自动计算)+第2个Label的bottom
2>viewDidLoad中设置tableView高度
self.tableView.rowHeight = UITableViewAutomaticDimension
self.tableView.estimatedRowHeight = 100;
3>heightForRowAtIndexPath方法和estimatedHeightForRowAtIndexPath方法
开启了iOS 8 的单元格自动高度特性后,这两个方法就不需要了,或者简单地返回一个UITableViewAutomaticDimension常量,代码如下:
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
override func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}