I have a TableView that has many cells of the same type but are different in size due to the text inside the cells. I am trying to only show one cell at a time in the TableView regardless of size (i.e. no overlap from two smaller ones). I have tried some AutoLayout but I'm not sure if I'm going at it the right way. The TableView's row height is set by automaticDimension
.
This is the largest the cell will ever get
These are the smallest the cells will ever get and as you can see, two cells of this size equal the same size of the large cell. I want to be able to show only one of these instead of two!
Thank you!
Asked
Active
Viewed 86 times
0

John
- 43
- 6
-
You can't use `automaticDimension` - you need your `heightForRow` function to the return the height of the tableview – Paulw11 Oct 29 '18 at 03:18
-
Gotcha @Paulw11. I just tried that but is there a way to maintain the nice size proportions of the smaller cells so they fill out the tableview without increasing empty space for the smaller cells? – John Oct 29 '18 at 03:25
-
A tableview will fill its height with cells. You could reduce the height of the tableview, or perhaps you could change the `contentInsets` of the tableview so that the cell was centred in the tableview (You need to calculate the insets so that the top edge and bottom edge are half of the tableview height - the cell height) – Paulw11 Oct 29 '18 at 03:29
-
https://stackoverflow.com/questions/30450434/figure-out-size-of-uilabel-based-on-string-in-swift – SPatel Oct 29 '18 at 04:14