- April 27, 2024
- 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.
Horizon SDK is a state of the art real-time video recording / photo shooting iOS library. Some of the features ...