Latest 0.3.1
License MIT
Platforms ios 8.0
Frameworks UIKit

contributions welcome


ExpyTableView is a re-write based on SLExpandableTableView. Takes some ideas, concepts and codes and regenerates them in Swift. Lets you create expandable table views as easily as its ancestor.

With ExpyTableView, you make an expandable table view by using multiple cells and inserting/deleting them(which can mean expanding and collapsing). With this approach, you will have a great chance in future design requests. All you will have to do is adding a new UITableViewCell and writing the code for it. You will easily have the new design.



  • iOS 8.0+
  • Swift 3.0+


ExpyTableView is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod 'ExpyTableView'

Or you can manually drag and drop the ExpyTableViewCell.swift to your project, then use it.

How to use

First of all, if you are using Interface Builder, set your table view’s class and module as ExpyTableView.’

Then start implementing required methods:

import ExpyTableView

class ViewController: ExpyTableViewDataSource {

  @IBOutlet weak var expandableTableView: ExpyTableView!

  // First, set data source for your table view.
  override func viewDidLoad() {
    expandableTableView.dataSource = self
    //Set delegate if you will implement any UITableViewDelegate or ExpyTableViewDelegate methods.
    //expandableTableView.delegate = self 

  // Then return your expandable cell instance from expandingCell data source method.
  func expandableCell(forSection section: Int, inTableView tableView: ExpyTableView) -> UITableViewCell {
    // This cell will be displayed at IndexPath with (section: section and row: 0)

You are ready to go with the setup above.

If you want, you can improve the implementation:

extension ViewController {
  //OPTIONAL DATA SOURCE METHOD, default is true for all sections.
  func canExpand(section: Int, inTableView tableView: ExpyTableView) -> Bool {
    return true //Return false if you want your section not to be expandable

You can use optional delegate method:

extension ViewController: ExpyTableViewDelegate {

  //OPTIONAL DELEGATE METHOD, receives callbacks when a section will expand, will collapse, did expand, did collapse. A unified method.
  func tableView(_ tableView: ExpyTableView, expyState state: ExpyState, changeForSection section: Int) {

    switch state {
    case .willExpand:
    print("WILL EXPAND")

    case .willCollapse:
    print("WILL COLLAPSE")

    case .didExpand:
    print("DID EXPAND")

    case .didCollapse:
    print("DID COLLAPSE")

If your header cell (which is section: section and row: 0) conforms to ExpyTableViewHeaderCell protocol which is optional, it gets notifications in changeState method:
(See example project for more detailed usage)

class YourTableViewCell: UITableViewCell, ExpyTableViewHeaderCell{

  //changeState method has a cellReuse parameter to allow you to prepare your cell for reusing. 
  //All state info is allocated by ExpyTableView.
  func changeState(_ state: ExpyState, cellReuseStatus cellReuse: Bool) {

    switch state {
    case .willExpand:
    print("WILL EXPAND")

    case .willCollapse:
    print("WILL COLLAPSE")

    case .didExpand: 
    print("DID EXPAND")

    case .didCollapse:
    print("DID COLLAPSE")

You can manually expand or collapse any section like below:

expandableTableView.expand(0) //Expand first section manually
expandableTableView.collapse(0) //Collapse first section manually

You will get callbacks for all of the UITableViewDataSource or UITableViewDelegate methods. Just conform to ExpyTableViewDataSource and ExpyTableViewDelegate and they will forward you all the methods you need.

extension ViewController{

  //All of the UITableViewDataSource and UITableViewDelegate methods will be forwarded to you right as they are.
  //Here you can see two examples below.
  func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    //If you don't deselect the row here, seperator of the above cell of the selected cell disappears.
    //Check here for detail:

    tableView.deselectRow(at: indexPath, animated: false)

    //This solution obviously has side effects, you can implement your own solution from the given link.
    //This is not a bug of ExpyTableView hence, I think, you should solve it with the proper way for your implementation. 
    //If you have a generic solution for this, please submit a pull request or open an issue.

    print("DID SELECT row: (indexPath.row), section: (indexPath.section)")

  func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    return UITableViewAutomaticDimension

See example code for more details and implementation examples.


To run the example project, just download the project and open the xcworkspace file in Example folder.


  • Add a variable that allows collapsing the recently expanded cell, when any other cell is expanded
  • Add a variable that allows scrolling to recent expanded cell rect to show it completely
  • Add a variable that allows clicking on any cell in section to expand or collapse the whole section
  • Add expandAll and collapseAll methods and functionality

All contributions about these issues or other improvements are really appreciated.


ExpyTableView is available under the MIT license. See the LICENSE file for more info.

Latest podspec

    "name": "ExpyTableView",
    "version": "0.3.1",
    "summary": "ExpyTableView lets you make your table view expandable with implementing one method.",
    "description": "ExpyTableView allows you to make your table view sections expandable just by implementing one data source method. Uses row insertion and deletion. You specify and return the expanding cell from this data source method and you are ready to go.",
    "homepage": "",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    "authors": {
        "okhanokbay": "[email protected]"
    "source": {
        "git": "",
        "tag": "0.3.1"
    "platforms": {
        "ios": "8.0"
    "source_files": "ExpyTableView/Classes/**/*",
    "frameworks": "UIKit",
    "pushed_with_swift_version": "3.0"

Pin It on Pinterest

Share This