I have a UITableView with a variable number of rows (cells) – the height of these rows is constant. What I would like is to make the height of the UITableView depend on the number of rows.
Also, I would like the UITableView to be exactly wrapping the cells, so no padding at the bottom. So if a cell has height 60, tableview should be 60 for one cell, 120 for two cells, etc…
Thanks in advance!
You could access your data source to find the number of cells that will be displayed. Multiply this number by the height of one row and you get the height of the entire table view. To change the height of a table view, you can change its frame property.
You can access the (constant) height of one row of your table view by accessing its
rowHeightproperty. If you fill your table view with the objects of an array calledmyArray, you could use the following code:You could also find out how many rows the table view will contain by asking the table view itself, instead of the data object. Something like this should work: