Latest 0.1.0
License MIT
Platforms ios 8.0

[![CI Status]( Merino/XMExpandableTableView.svg?style=flat)]( Merino/XMExpandableTableView)


XMExpandableTableView is a subclass of UITableViewController. It allows you to quickly implement a table view whose cells can expand. You can customize your cell to reflect changes when it expands and collapses.



  • iOS 8+


You can install XMExpandableTableView manually by simply copying XMExpandableTableView.swift into your project’s workspace.

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

pod "XMExpandableTableView"


  • In the Storyboard and drag a Table View Controller
  • Create a .swift file for the Table View Controller
  • Select the view and under the Identity Inspector select your newly created Swift file. Make sure that your file is set to inherit from UITableViewController.


  • Import XMExpandableTableView into your project.
import XMExpandableTableView
  • In your file, make sure to replace UITableViewController with XMExpandableTableView.
import UIKit
import XMExpandableTableView

class DemoTableViewController: XMExpandableTableView {
  • Let XMExpandableTableView know about the cells you want to expand by using super.rowModel.addRow(rowNumber, collapsedHeight: cHeight, expandedHeight: eHeight). You should do this for every row, even the ones you don’t plan on expanding. In the example provided below we want to be able expand the first two cells and leave the third one always collapsed.
override func viewDidLoad() {

    // Adding rows to the model
    super.rowModel.addRow(0, collapsedHeight: 83, expandedHeight: 174)
    super.rowModel.addRow(1, collapsedHeight: 83, expandedHeight: 174)

    // Setting the standard collapsed height to the default 44.
    super.rowModel.standardCollapsedHeight = 44
    super.rowModel.addRow(2, collapsedHeight: super.rowModel.standardCollapsedHeight, expandedHeight: super.rowModel.standardCollapsedHeight)
  • The rows will expand when selected. If you wish to do something else upon selection you must override the didSelectRowAtIndexPath provided by XMExpandableTableView. Make sure to call the XMExpandableTableView method to keep the expanding / collapsing functionality. An example is provided below.
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    // Keeps the expand / collapse behavior
    super.tableView(tableView, didSelectRowAtIndexPath: indexPath)

    // ExpandedRow will be -1 if no row is selected.
    let expandedRow = super.rowModel.getExpandedRow()

    // Your code goes here

  • If you want to delete a cell make sure to call super.tableView(tableView, commitEditingStyle: .Delete, forRowAtIndexPath: indexPath) to let XMExpandableTableView know that you are deleting a row. It will update its internal model and everything will work as intended. Also make sure to delete the content from your data source. An example is provided below.

Remove Row

override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
    if editingStyle == .Delete {
        // Makes XMExpandableTableView update its internal row model.
        super.tableView(tableView, commitEditingStyle: .Delete, forRowAtIndexPath: indexPath)
        // Make sure to delete the content from your data source as well.
        tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)

You can see the full example by following the steps in the Example section.


To run the example project, clone the repo, and run pod install from the Example directory first.


If you find any issues regarding this project let me know and file them in the Issues section. My email is below.


Xavier Merino, [email protected]


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

Latest podspec

    "name": "XMExpandableTableView",
    "version": "0.1.0",
    "summary": "This pod allows creating a UITableView whose cells can expand and collapse when selected. You can customize your cell as much as you want.",
    "description": "XMExpandableTableView provides a custom UITableViewController class that allows you to quickly implement a TableView that can expand its cells. Cells have a defined collapsed and expanded height. You can customize your cell accordingly.",
    "homepage": "",
    "screenshots": "",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    "authors": {
        "Xavier Merino": "[email protected]"
    "source": {
        "git": "",
        "tag": "0.1.0"
    "social_media_url": "",
    "platforms": {
        "ios": "8.0"
    "source_files": "XMExpandableTableView/Classes/**/*"

Pin It on Pinterest

Share This