Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

i want dynamic get uitableview total height,not uitableviewcell,

I want dynamic get uitableview total height,not UITableViewCell, not frame, and i find self.tableView.contentSize.height=0 for the first time, so i am very trouble in this problem,i need help please.

thanks...

like image 220
Harry Avatar asked Jul 01 '13 07:07

Harry


People also ask

How do you set the dynamic height of a table view cell?

Image view without an image selected has no intrinsic content size, hence we need to set an explicit height constraint for it. The key to achieve dynamic height table view cell is to let Auto Layout know how to calculate the height of the cell.

How do you find the height of a cell in Swift?

You need the cell for a certain IndexPath to calculate its bounds. You can do it this way in any of the delegate functions of the UITableView : let row = tableView. cellForRow(at: indexPath) let cellHeight = (row?.

What is tableView?

A table view displays a single column of vertically scrolling content, divided into rows and sections. Each row of a table displays a single piece of information related to your app. Sections let you group related rows together. For example, the Contacts app uses a table to display the names of the user's contacts.


2 Answers

You can use contentSize property of UITableView, but you should layout tableView first. Check this answer https://stackoverflow.com/a/2528123/1158590

like image 133
Numeral Avatar answered Oct 16 '22 22:10

Numeral


The self.tableView.contentSize.height is the proper way to do it, but you have to load the table view before calling this, so put a [tableView reloadData]; before calling self.tableView.contentSize.height.

like image 35
danypata Avatar answered Oct 17 '22 00:10

danypata