- August 28, 2025
- Mins Read
A Swift library that helps you collapse table view sections.
Just clone and add the following Swift files to your project:
pod --versionsudo gem install cocoapodspod init in you project root dirnano Podfile, add:
use_frameworks!
pod ‘CollapsibleTableSectionViewController’, ‘~> 2.0.1’
ctrl-x, y, enterpod update.xcworkspaceimport CollapsibleTableSectionViewController!nano Cartfilegithub "jeantimex/CollapsibleTableSectionViewController" ~> 2.0.1 into Cartfilectrl-x, y, entercarthage updateCollapsibleTableSectionViewController.framework from Carthage/Build/iOS to your projectCollapsibleTableSectionViewController is added in Embedded Binaries section of your target (or else you will get dyld library not loaded referenced from ... reason image not found error)import CollapsibleTableSectionViewController on top of your view controller’s code
import CollapsibleTableSectionViewController
class ViewController: CollapsibleTableSectionViewController { … }
extension ViewController: CollapsibleTableSectionDelegate { … }
Most of the protocol methods are optional and they are very similar to UITableViewDataSource and UITableViewDelegate, here is a list of the available protocol methods:
Asks the data source to return the number of sections in the table view. Default is 1.
extension ViewController: CollapsibleTableSectionDelegate {
func numberOfSections(_ tableView: UITableView) -> Int {
return 10
}
}
Returns the number of rows (table cells) in a specified section. Default is 0.
extension ViewController: CollapsibleTableSectionDelegate {
func collapsibleTableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 5
}
}
Returns the table cell at the specified index path. You can also use your custom cells, see our example projects for more details.
extension ViewController: CollapsibleTableSectionDelegate {
func collapsibleTableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: “Cell”) as UITableViewCell? ?? UITableViewCell(style: .default, reuseIdentifier: “Cell”)
cell.textLabel?.text = “Cell Text”
return cell
}
}
Return true if you would like collapse all the sections when the table is loaded. Default is false.
Return true if you would like to keep only one extended section (like accordion style). Default is false.
The title for each section. Default is nil.
Tells the delegate that the specified row is now selected.
Run the Examples project in this repo and you will find the following demos that help you get up and running:
For more details of how to implement collapsible table sections using Swift, please checkout this repo for more information: https://github.com/jeantimex/ios-swift-collapsible-table-section.
This package provides you with an easy way to show tooltips over any SwiftUI view, since Apple does not provide ...
SimpleToast is a simple, lightweight, flexible and easy to use library to show toasts / popup notifications inside iOS or ...
Create Toast Views with Minimal Effort in SwiftUI Using SSToastMessage. SSToastMessage enables you to effortlessly add toast notifications, alerts, and ...