简体   繁体   English

UITableView节的高度

[英]UITableView height of a section

I have a UITableView that has 3 sections. 我有一个UITableView有3个部分。 My individual cells vary in height (collapse-expand). 我的个体细胞高度不同(塌陷扩大)。 I need a way to figure out the height of each individual section, ie the sum of cell heights in each section. 我需要一种方法来计算每个部分的高度,即每个部分的细胞高度之和。 Preferably without calculating everything the tableView already has done each time I need it. 最好不计算每次我需要时tableView已经完成的所有操作。

I there a way to deduce or access such a value? 我有办法推断或获得这样的价值吗?

你看过-rectForSection :(也可能是-rectForFooterInSection:

There is no easy way to calculate the value, however there is a way. 没有简单的方法来计算价值,但有一种方法。 If your cells have a fixed height it's just the many rows multiplied by their fixed height for each section. 如果你的单元格有一个固定的高度,那么每个部分只有许多行乘以它们的固定高度。

If you have varying height in the cells too, I'd go for an array which holds the total height for each section, just calculate it once and keep it cached there. 如果你在单元格中也有不同的高度,我会选择一个数组来保存每个部分的总高度,只需计算一次并将其保存在那里。 If the section is collapsed you just need the section header height else it's the value in the array. 如果该部分是折叠的,您只需要节标题高度,否则它是数组中的值。

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

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