This is a Swift version of STCollapseTableView that was written in Objective-C.
CollapseTableView enables you to make expandable UITableView's sections with just a few lines of code.
pod 'CollapseTableView'
Just copy Source folder to your Xcode project.
After adding the framework to your project, you need to import the module
import CollapseTableView
Then you need to subclass your UITableView with CollapseTableView and set delegate/datasource as you always do. By default, tableView sections are clickable and expandable.
If you want to disable clickability of sections, there is a special property for this:
public var shouldHandleHeadersTap: Bool
So after you implement standard tableView's dataSource/delegate methods for sections, you will be able to open or close the sections with your cells by clicking them.
There're extra tableView methods for work with sections:
public func toggleSection(_ sectionIndex: Int, animated: Bool)
public func openSection(_ sectionIndex: Int, animated: Bool)
public func closeSection(_ sectionIndex: Int, animated: Bool)
public func isOpenSection(_ sectionIndex: Int) -> Bool
There's a closure to observe events for opening/closing sections:
tableView.didTapSectionHeaderView = { (sectionIndex, isOpen) in
}
- Exlusive sections mode (Max 1 opened section)
If you have any questions or suggestions, feel free to open issue just at this project.
CollapseTableView and all its classes are available under the MIT license. See the LICENSE file for more info.