問題
學習swift過程中遇到了個問題就是UITableView的高度自適應UITableViewAutomaticDimension
不起作用,并且還報了個 [Warning]
[Warning] Warning once only: Detected a case where constraints
ambiguously suggest a height of zero for a tableview cell's content view.
We're considering the collapse unintentional and using standard height instead.
通用代碼設置為:
self.tableView.estimatedRowHeight = 120
self.tableView.rowHeight = UITableViewAutomaticDimension
但運行效果卻為:
before.png
解決方法
google 一番之后,發(fā)現(xiàn)原來是我的cell里的控件沒有做bottom約束(AutoLayout),所以加上Bottom約束之后的效果為:
after.png
完美