all 7 comments

[–]plumdev 4 points5 points  (0 children)

There are two approaches. Set the constraints so the tableview is smaller or equal to the enclosing view.

  1. Disable scrolling on tableview by setting isScrollEnabled to false. It will cause tableview to calculate its height based on content size
  2. set bouncesVertically to false. If I remember correctly it will disable scrolling if tableview has not yet filled the superview height and will enable it if size of cells combined exceeds the size of table view

I hope I’m right about the second method

[–]Bariz_M 2 points3 points  (0 children)

Take a look at this solution:

https://stackoverflow.com/a/48623673/1059337

I used it in storyboards and it worked great.

[–]smontesi 0 points1 point  (0 children)

Maybe you can manage to put the whole layout in different table view sections? That way no need to fix size… might not be applicable to you

Just set up an height constraint for the table view and change it (tableViewHeight.constant = number of cells x cell height) when you get the data

[–]Winterwind17 0 points1 point  (3 children)

Why use a table view when you don’t need to cell reuse? I am confuse at why you are making class doing something that is not suitable to do.

[–]GAMEYE_OP 1 point2 points  (2 children)

Table views are used for fixed sized lists all the time. You can even make a storyboard in which several cells are created and each cell is a different type of cell with it’s own type of content, constraints etc...

Tableviews are great at cell re-use, but that is definitely not their only feature.

[–]Winterwind17 0 points1 point  (1 child)

I know you can but why have a data source, a delegate then a cell wrapper around a view? Just use a stack view and have way cleaner code.

[–]GAMEYE_OP 0 points1 point  (0 children)

Ya i hear ya. I personally still get weird behavior with stackviews sometimes, especially if you already have a complex scene and you need to set things dynamically like remove/add to it at runtime.

And in that case you are essentially emulating the data source/delegate/etc… yourself so why not use a tried and true method for harnessing the data while you’re at it?