- May 27, 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 --version
sudo gem install cocoapods
pod init
in you project root dirnano Podfile
, add:
use_frameworks!
pod ‘CollapsibleTableSectionViewController’, ‘~> 2.0.1’
ctrl-x
, y
, enter
pod update
.xcworkspace
import CollapsibleTableSectionViewController
!nano Cartfile
github "jeantimex/CollapsibleTableSectionViewController" ~> 2.0.1
into Cartfilectrl-x
, y
, enter
carthage update
CollapsibleTableSectionViewController.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.
Light and scrollable view controller for tvOS to present blocks of text Description TvOSTextViewer is a view controller to present ...
TvOSSlider is an implementation of UISlider for tvOS. Description and usage TvOSSlider palliates missing an implementation of UISlider for tvOS as part ...
TvOSScribble, based on CoreML, mitigates the lack of a physical numpad area in Siri Remote implementing a handwriting gesture recognizer. ...
PIN keyboard for tvOS Description TvOSPinKeyboard is a view controller that allows easily asking for PIN codes in tvOs Requirements ...
📺 A tvOS button which truncates long text with '... More'. The TvOSMoreButton is a simple view which aims to ...