Skip to content
This repository was archived by the owner on Nov 5, 2020. It is now read-only.
This repository was archived by the owner on Nov 5, 2020. It is now read-only.

Support UITableView moveSection:toSection: #20

@rholstad

Description

@rholstad

Visible sections is not updated when using moveSection:toSection:. So, if you try to move a section that is expanded to a location of a section that is not expanded, it will crash. I wrote an override for moveSection:toSection which works, but only for single moves. It will not work when moving multiple sections using performBatchUpdates:completion: or beginUpdates() and endUpdates().

override open func moveSection(_ section: Int, toSection newSection: Int) {
    let sectionIsVisible = visibleSections[section] ?? false
    visibleSections.removeValue(forKey: section)
    if (newSection < section) {
        for i in stride(from:section - 1, through:newSection, by:-1){
            visibleSections[i+1] = visibleSections[i] ?? false
        }
    }else if (section < newSection){
        for i in stride(from:section + 1, through:newSection, by:1){
            visibleSections[i-1] = visibleSections[i] ?? false
        }
    }
    visibleSections[newSection] = sectionIsVisible
    super.moveSection(section, toSection: newSection)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions