且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何让UITableView行高自动调整大小到UITableViewCell的大小?

更新时间:2023-12-04 13:01:40

如果所有单元格都是同样,将 UITableView 上的 rowHeight 属性设置为单元格的大小。如果它们根据内容完全不同,那么您将不得不实现 -tableView:heightForRowAtIndexPath:并根据您的数据源计算每行的高度。 / p>

How to get a UITableView row height to auto-size to the size of the UITableViewCell?

So assuming I'm creating the UITableViewCell in Interface Builder, and it height is more than the standard size, how can I get the UITableView row height to autosize to it? (i.e. as opposed to manually having to measure the height in interface builder and than programmatically setting it)

If all the cells are the same, set the rowHeight property on UITableView to the size of your cell. If they're all different based on content, you're going to have to implement -tableView:heightForRowAtIndexPath: and calculate the height for each row based on your data source.