2

I'm using a UICollectionView inside of a UITableViewCell. It's all working fine, but i have some issues with Auto Layout. The UICollectionView should just show the cells without horizontal or vertical scrolling.Because now I have a the scrollable UICollectionView inside my UITableViewCell the following code doesn't work for me to get the dynamic table cells' height for this cell, but for other cells.

self.tableView.rowHeight = UITableViewAutomaticDimension
self.tableView.estimatedRowHeight = 44

I unchecked the option "scrolling enabled" in storyboard, but the result is, that i just can't scroll and don't see the rest of my collectionView. Right now I simply set constraints from my UICollectionView to the UITableViewCell to all edges, but it's not working.

Would be great if someone have an idea.

Thanks a lot.

Lucas Huang
  • 3,888
  • 3
  • 17
  • 29
Philipp B.
  • 113
  • 1
  • 1
  • 4

2 Answers2

1

You'll need to have a height constraint set on your UICollectionView. If you've just pinned your UICollectionView to your UITableViewCell, it's getting its height from the table cell and the table cell is getting its height from the collection cell, so neither really knows what to do in that situation.

Lucas Huang
  • 3,888
  • 3
  • 17
  • 29
Clint Martin
  • 201
  • 4
  • 5
  • 1
    Hey, thank you. Tried your solution, but for now its not the result i try to achieve. I tried a fixed height for my UICollectionView and then pinned a button constraints to my UITableViewCell. Ended up in a constraint conflict. When i set a fixed height for my UICollectionView, its not dynamic anymore. The height of the UICollectionView should be dynamic to the number of cells which are currently displayed. Then the UITableViewCell should getting its height dynamically from the UICollectionView – Philipp B. Sep 15 '15 at 10:21
  • 1
    I don't think there is a fully-dynamic solution for what you're trying to achieve. The collection view won't resize itself in such a way that it will tell the tableviewcell to resize as well. The easiest solution here is to have a height constraint set on your collection view. When you dequeue your tableview cell, reload your collection view in the cell then find its full height via `cell.collectionView.layout.contentViewSize.height` (using your own variable names). Set the height constraint to this value. Your tableView cell should resize to the collection view height. – Clint Martin Sep 15 '15 at 15:08
  • I'm facing the exact same problem and this is driving me mad. Did you ever solve it? – Performat Jan 29 '16 at 14:25
0

I did meet a similar issue before. It turned out that I haven't fully set up the relationship between the UITableViewCell and its containing elements so that they don't know how far to grow. I don't think this is related to embedded scrolling view. Just make sure that you have constraints set up between the UI elements inside the UITableViewCell and the bottom of UITableViewCell.

Lucas Huang
  • 3,888
  • 3
  • 17
  • 29