Swift library to support collapsible sections in a table view.

Overview

CollapsibleTableSectionViewController

Platform Swift 4.2 CocoaPods Carthage compatible Build codecov.io License Donate

A Swift library that helps you collapse table view sections.

cover

Features

  • Support collapsible sections in a table view
  • Collapse all the sections by default (configurable)
  • Keep only one section expanded (configurable)
  • Auto resize table view cell
  • Easy-to-use protocols for configuration

Requirements

  • iOS 9.0+
  • Xcode 10.0+
  • Swift 4.2

Installation

Manual

Just clone and add the following Swift files to your project:

  • CollapsibleTableSectionViewController.swfit
  • CollapsibleTableViewHeader.swift

Cocoapods

  • Make sure that you use latest stable Cocoapods version: pod --version
  • If not, update it: sudo gem install cocoapods
  • pod init in you project root dir
  • nano Podfile, add:
use_frameworks! 
pod 'CollapsibleTableSectionViewController', '~> 2.0.1'
  • Save it: ctrl-x, y, enter
  • pod update
  • Open generated .xcworkspace
  • Don't forget to import CollapsibleTableSectionViewController: import CollapsibleTableSectionViewController!

Carthage

  • nano Cartfile
  • put github "jeantimex/CollapsibleTableSectionViewController" ~> 2.0.1 into Cartfile
  • Save it: ctrl-x, y, enter
  • Run carthage update
  • Copy CollapsibleTableSectionViewController.framework from Carthage/Build/iOS to your project
  • Make sure that CollapsibleTableSectionViewController 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)
  • Add import CollapsibleTableSectionViewController on top of your view controller's code

Usage

Step 1. Subclass CollapsibleTableSectionViewController

import CollapsibleTableSectionViewController

class ViewController: CollapsibleTableSectionViewController { ... }

Step 2. Conforms to the CollapsibleTableSectionDelegate protocol

extension ViewController: CollapsibleTableSectionDelegate { ... }

CollapsibleTableSectionDelegate Protocol

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:

1. optional func numberOfSections(_ tableView: UITableView) -> Int

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
  }
}

2. optional func collapsibleTableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int

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
  }
}

3. optional func collapsibleTableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell

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
  }
}

4. optional func shouldCollapseByDefault(_ tableView: UITableView) -> Bool

Return true if you would like collapse all the sections when the table is loaded. Default is false.

5. optional func shouldCollapseOthers(_ tableView: UITableView) -> Bool

Return true if you would like to keep only one extended section (like accordion style). Default is false.

6. optional func collapsibleTableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String?

The title for each section. Default is nil.

7. optional func collapsibleTableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)

Tells the delegate that the specified row is now selected.

Examples

Run the Examples project in this repo and you will find the following demos that help you get up and running:

  1. Basic: The minimal working example
  2. Custom Cell: Implement a custom cell programmatically
  3. Collapse By Default: All sections are collapsed by default
  4. Collapse Others: Accordion-style table view that only keeps one section expanded at a time

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.

Contribution

Anyone who would like to contribute to the project is more than welcome.

  • Fork this repo
  • Make your changes
  • Submit pull request

License

MIT License

Copyright (c) 2017 Yong Su @jeantimex

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Comments
  • Custom section header view

    Custom section header view

    At the moment, the section header looks like this:

    screen shot 2017-08-04 at 8 43 47 am

    it will be really nice if we can allow user to specify their own view/design.

    I guess what we can do is to bubble up the func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? protocol method to the user, and then wrap the UIView that is provided by the user and hook up the tag gesture which triggers the collapse action. And that will make this pod even better.

    enhancement 
    opened by jeantimex 1
  • More customization options, bug fixes, and future compatibility.

    More customization options, bug fixes, and future compatibility.

    1. Changed the arrowLabel to arrowImageView, so it can be changed by whom ever is using this framework. added a default arrow for the framework that is less pointy than >.
    2. Added a color value for the arrow so devs can change the color of the arrow easier, no matter what icon they are using.
    3. Added a section background color value so devs can change the background color of the collapsable section.
    4. Added an alignment value that changes the alignment of the section label AND changes the position of the arrow depending on left or right, so this framework can support languages like Persian or Arabic since they are right to left aligned.
    5. Changed how the animation for the arrow rotating was written, (used CGAffineTransform) which resulted in a smoother animation and removed the bug that displayed no animation when rotating back up. (collapsed)
    6. Removed a bug that would reset the arrow to collapsed mode even though the section was still open. (this occurred when an open section would get redrawn when going outside the visible view)
    7. Resolved every single warning that happened when setting the minimum deployment target above iOS 11, removed deprecated code if iOS version meets the requirement, and changed the swift version to swift 5.
    8. Updated travis.yml to test on newer iOS versions on a newer Xcode version.
    opened by shadow-of-arman 1
  • Activating Open Collective

    Activating Open Collective

    Hi, I'm making updates for Open Collective. Either you or another core contributor signed this repository up for Open Collective. This pull request adds financial contributors from your Open Collective https://opencollective.com/CollapsibleTableSectionViewController โค๏ธ

    What it does:

    • adds a badge to show the latest number of financial contributors
    • adds a banner displaying contributors to the project on GitHub
    • adds a banner displaying all individuals contributing financially on Open Collective
    • adds a section displaying all organizations contributing financially on Open Collective, with their logo and a link to their website

    P.S: As with any pull request, feel free to comment or suggest changes.

    Thank you for your great contribution to the Open Source community. You are awesome! ๐Ÿ™Œ And welcome to the Open Collective community! ๐Ÿ˜Š

    Come chat with us in the #opensource channel on https://slack.opencollective.com - great place to ask questions and share best practices with other Open Source sustainers!

    opened by monkeywithacupcake 1
  • Tableview scroll down dimension error

    Tableview scroll down dimension error

    img_5969duz img_5969duz1


    Tableview in section does not prevent the scroll position of the animation in dimension change to go to the negative values. If the tableview data exceeds the screen, the screen slides from top to bottom when the bottom section is opened and closed.

    opened by Semasancar 1
  • Tap on section does nothing at all

    Tap on section does nothing at all

    Hi, I have successfully display the sections and child cells correctly based on your example. But when I tap on the section header the cell is not expand or collapse, I follow all the guide on the example but I still failed, any idea what I miss out or what? Thanks

    opened by kamenr 1
Releases(1.0.1)
Owner
Su
Su
โœจ Awesome expandable, collapsible tableview cell for iOS written in Swift 5

ExpandableCell Intoduction Fully refactored YNExapnadableCell with more concise, bug free. Easiest usage of expandable & collapsible cell for iOS, wri

Kyle Yi 728 Jan 1, 2023
Make your table view expandable just by implementing one method.

ExpyTableView About ExpyTableView is a re-write based on SLExpandableTableView. Takes some ideas, concepts and codes and regenerates them in Swift. Le

Okhan Okbay 359 Dec 27, 2022
Savory is swift accrodion view implementation

Savory Savory is a swift accordion view implementation. Requirements Xcode 8.0 Swift 3.0 iOS 8 Installation Using CocoaPods: pod 'Savory', :git => 'ht

Nandin Borjigin 4 May 30, 2019
Three Level Accordian View for IOS

ThreeLevelAccordian ThreeLevelAccordian is a three level accordian for IOS. It owes its base code to SwiftyAccordionCells. Most of the design is custo

Amrata Baghel 44 Sep 23, 2022
`SimpleExpandableView` is a SwiftUI view which can collapse and expand the content

SimpleExpandableView ไธญๆ–‡่ฏดๆ˜Ž ExpandableView structure Example ExpandableView( headerSize: CGSize(width: 250.0, height: 50.0), cardSize: CGSize(wi

Tomortec 5 Oct 6, 2022
๐Ÿ”ฅ ๐Ÿ”ฅ ๐Ÿ”ฅSupport for ORM operation,Customize the PQL syntax for quick queries,Support dynamic query,Secure thread protection mechanism,Support native operation,Support for XML configuration operations,Support compression, backup, porting MySQL, SQL Server operation,Support transaction operations.

?? ?? ??Support for ORM operation,Customize the PQL syntax for quick queries,Support dynamic query,Secure thread protection mechanism,Support native operation,Support for XML configuration operations,Support compression, backup, porting MySQL, SQL Server operation,Support transaction operations.

null 60 Dec 12, 2022
A component to quickly scroll between collection view sections

SectionScrubber The scrubber will move along when scrolling the UICollectionView it has been added to. When you pan the scrubber you 'scrub' over the

Elvis 190 Aug 17, 2022
Collapse and expand UICollectionView sections with one method call.

This library provides a custom UICollectionView that allows to expand and collapse sections. Provides a simple API to manage collection view appearanc

Touchlane 172 Dec 26, 2022
โœจ Awesome expandable, collapsible tableview cell for iOS written in Swift 4

USE ExpandableCell. New version of this library. YNExpandableCell Updates See CHANGELOG for details Intoduction Easiest usage of expandable & collapsi

Kyle Yi 457 Dec 26, 2022
โœจ Awesome expandable, collapsible tableview cell for iOS written in Swift 5

ExpandableCell Intoduction Fully refactored YNExapnadableCell with more concise, bug free. Easiest usage of expandable & collapsible cell for iOS, wri

Kyle Yi 728 Jan 1, 2023
XLForm is the most flexible and powerful iOS library to create dynamic table-view forms. Fully compatible with Swift & Obj-C.

XLForm By XMARTLABS. If you are working in Swift then you should have a look at Eureka, a complete re-design of XLForm in Swift and with more features

xmartlabs 5.8k Jan 6, 2023
Using UI Table View With Swift

News-App - Apple ๊ด€๋ จ ๊ธฐ์‚ฌ๋ฅผ ๋ณด์—ฌ์ฃผ๋Š” News app์„ ๋งŒ๋“ค ๊ฒƒ์ž…๋‹ˆ๋‹ค. - ์ž์„ธํ•œ ๊ณผ์ •์€ ๋ฆฌ๋“œ๋ฏธ์— ์žˆ์Šต๋‹ˆ๋‹ค. Table View์™€ Table view controller Table View : Table์˜ ํฌ๊ธฐ๋ฅผ ์ง€์ •ํ•  ์ˆ˜ ์žˆ๋‹ค. Table View Co

Jiwon 0 Dec 9, 2021
TableViews - Emoji Table View For iOS With Swift

TableViews Hello! This is EmojiTableView. Let me introduce you my first app when

null 0 Jan 2, 2022
Use Yelp API to fetch restuarants around a location and show them in a table view

Yelp Use Yelp API to fetch restuarants around a location and show them in a table view - Infinite scrolling, Prefetching, Image Caching. Design Patter

null 0 Nov 1, 2021
Using UI Table View

News-App Table View์™€ Table view controller Table View : Table์˜ ํฌ๊ธฐ๋ฅผ ์ง€์ •ํ•  ์ˆ˜ ์žˆ๋‹ค. Table View Controller: ์ „์ฒด์˜ ๋ทฐ๊ฐ€ ํ•˜๋‚˜์˜ ํ…Œ์ด๋ธ” Table View Table view ๊ตฌ์„ฑ์š”์†Œ ๊ฒฐ์ •ํ•˜๊ธฐ ์–ด๋–ค

Jiwon 0 Dec 9, 2021
Typed, yet Flexible Table View Controller

ConfigurableTableViewController Simple view controller that provides a way to configure a table view with multiple types of cells while keeping type s

Arek Holko 270 Oct 15, 2022
Generic table view controller with external data processing

FlexibleTableViewController Swift library of generic table view controller with external data processing of functionality, like determine cell's reuse

Dmytro Pylypenko 9 May 20, 2018
A UITableView extension that enables cell insertion from the bottom of a table view.

ReverseExtension UITableView extension that enabled to insert cell from bottom of tableView. Concept It is difficult to fill a tableview content from

Taiki Suzuki 1.7k Dec 15, 2022
Make your table view expandable just by implementing one method.

ExpyTableView About ExpyTableView is a re-write based on SLExpandableTableView. Takes some ideas, concepts and codes and regenerates them in Swift. Le

Okhan Okbay 359 Dec 27, 2022