Resize tableview cell by updating table datasource dynamically - ios

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

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

Nested UITableView With Automatic Dimension

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.

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.

Dynamic Height for UITableview

i have a tableview with a dynamic changing number of cells. sometimes there are 10, another time more than 20 cells.
This Tableview is on a Viewcontroller, but i have so much content on this tableview, so my tableview and all other content are on a scrollview. now i have a double scroll. on on my scrollview, and another on my tableview and this is quite uncomfortable. so how can i set the height of my tableview dynamically?
If you are using Autolayout with storyboard then set constraints of your tableview
let Count = CGFloat(dataArray.count)
constraintsTblHeight.constant = Count*100 //100 is your tablview's cell height
other wise increase this height in tablview height

Resources