Nested UITableView With Automatic Dimension - ios

I have a screen that contains 2 levels of nested UITableViews.
Each cell of the outer (top level) TableView is a UITableViewCell That contains a UITableView.
The TableView inside each cell is drawn correctly, all constraints implemented properly UITableViewAutomaticDimension is performing correctly.
The problem is with the top level TableView cells height, Im trying to set their height with:
table.estimatedRowHeight = 400
table.rowHeight = UITableViewAutomaticDimension
and also return UITableViewAutomaticDimension in heightForRow.
Cells get height of 45 when their height is 400 or so (dynamic height for each cell).
What am I missing here?
Could it be that the top level TableView just cant estimate the inner cell height?
Help would be much appreciated

Have a look at this Tableview Inside Cell . It contains table view inside cell that is completely constructed using auto layout. Hope this may help.

Related

Custom TableView does not set a custom height for custom TableViewCell

I am trying to make a custom TableViewCell for a tableview, and the size is 414x350. The problem I am having is when table view get loaded all the sizes are squeezed and not right. I have tried all of the followings:
Assigning row height from code
tableView.estimatedRowHeight = 350
tableView.rowHeight = UITableView.automaticDimension
Assigning row height from storyboard in tableview window
Assigning row height from storyboard in tableviewcell window
The result is still the same. Any help is appreciated!
For any cell's automatic row dimension to be calculated properly, in your Storyboard you must have a direct line of vertical constraints between every item that goes all the way from the top to the bottom. If you set the constraints yourself, same thing applies.
Don't assign any row heights, except the estimated.

nested tableview with automatic dimension

I have a TableView that its cell contains a second TableView (Nested TableView).
Inner tableView shows comments that have variable cell height. Calculate this height with UITableView.automaticDimension.
But main tableView cannot calculate it's cell height properly.
Main tableView use UITableView.automaticDimension for calculating cell height. but innerTableView doesn't show in the main tableView.
My test project download link:
dropbox.com/s/woieoi71t5kt66d/NestedTableViewTest%202.zip?dl=0

Resize tableview cell by updating table datasource dynamically

I'm displaying information fetched from a server on tableview. My tableview cell view has two vertical stackviews placed horizontally in a content view. Each stackview has 6 items and depending on data I'm hiding and showing the stackview item and setting the stackview and content view height depending on content of stackview visible items. This is all working fine and the tableview is also looking good.
Now I have a feature to delete tableview rows on swipe of a tableview row. So after deleting any row and reloading tableview cells, tableview cell height is not getting set and shrinks.
Can anyone help me with how do I update tableview height after each reload? I've tried all possible solutions but none of them worked to me.
Try the following, in your viewDidLoad set:
tableView.estimatedRowHeight = 60 // this is an estimation but try and get it close to what the actual height may be
tableView.rowHeight = UITableViewAutomaticDimension
Then in the tableView heightForRowAt indexPath return this:
return UITableViewAutomaticDimension

how do I make tableviewcell height to autogrow

I have a tableviewcell with two labels and the label's height will change depending on the content so tableviewcell height will automatically change.
now how can I make tableview cell height to autogrow ?
Please clarify me if the tableview cell height will autogrow if the label height changes ?
To make it tableview cell autogrow you have to keep in mind of the following two things in mind,
Right constraint(top, bottom, right & left) for the UI elements inside the tableview cell.
Usage of UITableViewAutomaticDimension & estimatedRowHeight property as follows,
tableView.estimatedRowHeight = 100 // A rough estimated height for your cell.
tableView.rowHeight = UITableViewAutomaticDimension
Refer the following tutorial for better indepth explanation on how to implement it.
http://matteomanferdini.com/the-correct-way-to-display-lists-in-ios-and-what-many-developers-do-wrong/#autolayout
https://www.youtube.com/watch?v=e1KJQs0frbM

Auto set height of table view based on UICollectionView inside it

I have a UITableView with cells that have inside a UICollectionView.
Now all works great except of UICollectionViewCell scrolling i want that the height of table view cell follow the Collection view cell content.
In simple word i want scrolling in table view but not inside single cell i need to display all contents of UIcollectionViewCell without scrolling inside it.
Thanks
You have to calculate the collectionviews' heights and set a height constraint on each of them. then add top and bottom constraints from the collectionviews to their superviews (the tableviewcells / their contentviews) and let autolayout do its work.
don't forget
tableView.estimatedRowHeight = 44 // or something similar
tableView.rowHeight = UITableViewAutomaticDimension
in the controller's viewDidLoad to make the automatic row height calculation work.

Resources