ios-swift-collapsible-table-section
ios-swift-collapsible-table-section copied to clipboard
Headers from 1 section overlapping into text from another section
I made my table sections auto collapse when you open any other section via for loops. One of my testers sent me these screenshots showing that the various fields from each section seem to get overlapped by headers from other sections.
I used the exact code from this repository and changed only a few lines of code to make the sections auto close and customized the data in ExampleData.swift.
In the CollapsibleTableViewController.swift, I added this into viewDidLoad:
for index in 0 ..< sections.count {
sections[index].collapsed = true
}
I updated my toggleSelection code as follows:
func toggleSection(_ header: CollapsibleTableViewHeader, section: Int) {
let collapsed = !sections[section].collapsed
print("section = \(section)")
// Toggle collapse
print("toggle collapse")
sections[section].collapsed = collapsed
print("sections.count = \(sections.count)")
let count = sections.count - 1
for index in 0 ... count {
if index != section {
sections[index].collapsed = true
}
}
header.setCollapsed(collapsed)
tableView.reloadSections(IndexSet(integersIn: 0...sections.count-1), with: .automatic)
}
Here is the screenshot of the bug in action: image
Any ideas what could be causing this? I can't replicate this in my testing but my tester keeps having this happen.
Thanks
Update: been investigating this and it appears to be caused by iOS 11 changing how tableview estimated heights are handled.
If I figure out a fix, will post it.
Thank you so much @DrD00der!
Also I am thinking upgrading to Swift 4
Problem solved:
Remove the sizing from viewDidLoad and add them in viewWillAppear:
override func viewWillAppear(_ animated: Bool) {
tableView.estimatedRowHeight = 75
tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedSectionFooterHeight = 75
tableView.sectionFooterHeight = UITableViewAutomaticDimension
tableView.estimatedSectionHeaderHeight = 75
tableView.sectionHeaderHeight = UITableViewAutomaticDimension
}
overlapping when expanding section
is it any solution regarding overlapping problem
for better understanding see attachment file
UITableViewAutomaticDimension never works on my project in term of setting proper section header height.
Problem solved:
Remove the sizing from viewDidLoad and add them in viewWillAppear:
override func viewWillAppear(_ animated: Bool) { tableView.estimatedRowHeight = 75 tableView.rowHeight = UITableViewAutomaticDimension tableView.estimatedSectionFooterHeight = 75 tableView.sectionFooterHeight = UITableViewAutomaticDimension tableView.estimatedSectionHeaderHeight = 75 tableView.sectionHeaderHeight = UITableViewAutomaticDimension }
Why is this a fix?