简体   繁体   中英

UITableView height of a section

I have a UITableView that has 3 sections. 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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