简体   繁体   中英

Calculate dynamic height of uitableviewcell

I'm searching too many questions related to increasing height of UITableViewCells but I can't get exactly what I want.

I have to calculate dynamic height of UITableViewCell . But, problem is in my cell there is a dynamic number of buttons, ranging from 1 to 100. I don't know how many buttons will show beforehand. So how can we calculate the height?

One way you could do is that you can have a global variable, for ex: cellHeight, and then change the cellHeight dynamically when you are customising your cell.

finally, return the cellHeight

- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return cellHeight;
}`

There are Two Way for get size of UITableViewCell

1) cell.bounds.size.height 
2) cell.contentView.frame.size.height

It depending on which you actually need.

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