Reputation: 433
I have UIStackView in UITableViewCell and have four long text labels in it. In first load I show only first label with 44 height in cell and hide other three and StackView shows properly.Then when I click on tableViewCell I need to expand cell and show other three labels. I show them and reload TableView but my StackView has zero height after that and all four label have zero height too. I hit this problem only with IOS 10.1 and when I use labels with short text StackView work well.
This is my code:
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
var cell = tableView.cellForRowAtIndexPath(indexPath) as! AboutUsTableViewCell
cell.firstLabel.hidden = isExpanded
cell.secondLabel.hidden = isExpanded
cell.thirdLabel.hidden = isExpanded
isExpanded = !isExpanded
tableView.reloadData()
}
Thank you all!
Upvotes: 1
Views: 1650
Reputation: 1248
You should update table after changing isHidden
properties. That's should do a trick.
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
var cell = tableView.cellForRowAtIndexPath(indexPath) as! AboutUsTableViewCell
cell.firstLabel.hidden = isExpanded
cell.secondLabel.hidden = isExpanded
cell.thirdLabel.hidden = isExpanded
isExpanded = !isExpanded
tableView.beginUpdates()
tableView.endUpdates()
}
Also, check this article about using UIStackView
inside UITableView
cells
Upvotes: 1
Reputation: 7903
Set the Labels number of lines to 0 and add below code to the viewDidLoad method.
self.tableView.estimatedRowHeight = 44.0 //or cell height
self.tableView.rowHeight = UITableViewAutomaticDimension
Upvotes: 0