UITableView inside UITableViewCell height not working as expected

0 votes
asked Sep 11, 2017 by ppgdev

I have a UITableView which have some cells that will be always be there, one cell with a UICollectionView in it that will act like tabs, and finally one cell with a UITableView in it, whose data will change.

Then when the user selects one of this "tabs", I want to reload the nested table to show the correct data rows (the height of this rows will be dynamic).

I have already achieved that the nested table changes on the collection item selection, but the problem I am facing is that the UITableView inside the cell is not sizing properly.

I have build a sample app just to simplify the views. As you can see in the screenshot, the cell that contains the table is not filling the rest of the screen, so the 10 rows are not visible unless you scroll this table.

Screenshot 1

Screenshot 2

What I want is this table to fill the rest of the screen. The user must be able to scroll the main tableview, not the nested one, and still see all of the nested table cells.

I can't do this with multiple sections because I will have a header section that will be always fixed on top, if I had another section, it's header will replace the sticky one on scroll.

I have set the rowHeight of the main UITableView to UITableViewAutomaticDimension and an estimatedRowHeight too. I have pinned it to top, left, right and bottom of the cell's ContentView.

Can you help me with this, please? If it helps, I could upload the sample project and link it here.

Thank you very much!

1 Answer

0 votes
answered Sep 11, 2017 by kavyakavita

If you are using autolayout then,

Give height constant to nested table view, create outlet for that height constraint.

When you reload that nested table, you will get that table's content size.

Fetch height from that content size and modify height constraint.

Welcome to Q&A, where you can ask questions and receive answers from other members of the community.
Website Online Counter