UICollectionView inside of UITableViewCell - AutoLayout

守給你的承諾、 提交于 2020-01-13 19:27:09

问题


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.


回答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.




回答2:


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.



来源:https://stackoverflow.com/questions/32574881/uicollectionview-inside-of-uitableviewcell-autolayout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!