简体   繁体   English

自动布局uitableview自动高度

[英]Autolayout uitableview auto height

I have following design. 我有以下设计。

在此处输入图片说明

Using AutoLayout but TableView only shows a portion of the items 使用自动版式,但TableView仅显示部分项目

let animals: [String] = ["Horse", "Cow", "Camel", "Sheep", "Goat"]

在此处输入图片说明

I need all the items are displayed 我需要显示所有项目

You have to change the tableview height according to your data count.Here 5 animals name ,so 5 * each cell height ,give to table view height then it works. 您必须根据数据计数更改表格视图的高度。这里有5个动物的名字,所以每个单元格的高度为5 *,赋予表格视图的高度即可。 In your view ,height of tableview not enough to show all details. 在您看来,tableview的高度不足以显示所有详细信息。

Set Constraints properly so that TableView can calculate height properly, now set 正确设置约束,以便TableView可以正确计算高度,现在设置

tableView.estimatedRowHeight = 300 //Height you think you cell can have
tableView.rowHeight = UITableViewAutomaticDimension

if still need return UITableViewAutomaticDimension in tableView delegate HeightForRow. 如果仍然需要在tableView委托HeightForRow中返回UITableViewAutomaticDimension。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM