ios-swift-collapsible-table-section icon indicating copy to clipboard operation
ios-swift-collapsible-table-section copied to clipboard

Headers from 1 section overlapping into text from another section

Open DrD00der opened this issue 7 years ago • 7 comments

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

DrD00der avatar Oct 24 '17 01:10 DrD00der

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.

DrD00der avatar Oct 25 '17 20:10 DrD00der

Thank you so much @DrD00der!

jeantimex avatar Oct 26 '17 17:10 jeantimex

Also I am thinking upgrading to Swift 4

jeantimex avatar Oct 26 '17 17:10 jeantimex

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
    }

DrD00der avatar Oct 27 '17 00:10 DrD00der

img_0097 overlapping when expanding section is it any solution regarding overlapping problem

for better understanding see attachment file

sourabh31 avatar Dec 27 '17 12:12 sourabh31

UITableViewAutomaticDimension never works on my project in term of setting proper section header height.

AdminOfUbriter avatar Mar 10 '18 20:03 AdminOfUbriter

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?

adamirowe avatar Jan 22 '19 18:01 adamirowe