I have a UIStackView
inside UITableViewCell
's contentView
. Based on user interaction, I add/remove items in the UIStackView
. After modifying the items in UIStackView
, I expect the cell
to update it's height accordingly. But, it doesn't update it's height unless I call tableView.reloadData()
. But, calling reloadData()
in cellForRowAtIndexPath
/ willDisplayCell
becomes recursive.
What is the proper way to adjust the cell
height at run time based on items in UIStackView
?
I use UITableViewAutomaticDimension
Updating the Problem:
Here is a simple prototype of what I am trying to do.
My actual problem is dequeuing the cell.
In the prototype, I have 2 reusable cells and 3 rows. For row 0 and 2, I dequeue cellA
and for row 1, I dequeue cellB
. Below is the overview on the condition I use.
if indexPath.row == 0 {
// dequeue cellA with 2 items in stackView
}
if indexPath.row == 1 {
// dequeue cellB with 25 items in stackView
}
if indexPath.row == 2 {
// dequeue cellA with 8 items in stackView
}
But the output is,
row 0 contains 2 items in stackView
- expected
row 1 contains 25 items in stackView
- expected
row 2 contains 2 items in stackView
- unexpected, row 0 is dequeued
I also tried removing all arranged subViews of stackView
in cellForRowAtIndexPath
. But, doing so, flickers the UI when scrolling. How can I manage to get the desired output?