Table View with height of different cells and adjustable to their contents

0

I'm trying to make a view that contains a TableView with different cells of different heights that fit their content. But I do not find any example that works well.

What I do is implement a tableView with a cell prototype to which I do not declare height. I'm filling content with a collectionView with different items that if they exceed the total cell width of tableView make a jump to the next line with a scrollVertical .

I add the following code to viewDidLoad() to do a vertical readjustment of the cell but it does not work:

tableView.estimatedRowHeight = 100
tableView.rowHeight = UITableViewAutomaticDimension
    
asked by Popularfan 22.09.2017 в 11:11
source

1 answer

2

To understand how UITableViewAutomaticDimension works this tutorial explains the basics pretty well: link

Respect to put a collectionview within a cell of a tableview a priori would say that it is not the best solution. If the elements are also placed with a vertical scroll, at the end it sounds like you need to put more elements in your tableview. You could use the sections , to put a variable number of elements according to the section you are in (at the end the x elements that you would put in your collectionview would become x tableviewCell in each seccion ).

If in spite of everything you want to continue with your approach, I think what you will need is to calculate the number of elements that will contain your collectionview , and the height that they add up between all, to assign that height to your collectionview and block the scroll of your collectionview .

collectionView.isScrollEnabled = false

Finally, you will have to add constraints to your colectionView to refer to the top and bottom of your tableviewCell , so that it knows how to calculate its height (as the tutorial will explain)

    
answered by 27.09.2017 в 12:30