Swift library to easily show, hide and customize table view cells as an expandable list of items.
- iOS 7.0
- UIKit
-
Implement your UITableViewController class with ExpandableTableViewController and ExpandableTableViewDatasource, ExpandableTableViewDelegate protocols.
class DemoTableViewController: ExpandableTableViewController, ExpandableTableViewDelegate, ExpandableTableViewDatasource { ... }
-
In your Storyboard, connect the IBOutlet expandableTableView with your current UITableView object.
Image
-
In your Storyboard, set the UITableView object with the ExpandableTableView class.
Image
-
Set the expandableDatasource and expandableDelegate properties to self in your viewDidLoad()
override func viewDidLoad() { super.viewDidLoad() self.expandableTableView.expandableDelegate = self self.expandableTableView.expandableDatasource = self }
-
Add and implement the ExpandableTableViewDatasource required methods:
// Rows func expandableTableView(expandableTableView: ExpandableTableView, numberOfRowsInSection section: Int) -> Int func expandableTableView(expandableTableView: ExpandableTableView, cellForRowAtExpandableIndexPath expandableIndexPath: ExpandableIndexPath) -> UITableViewCell func expandableTableView(expandableTableView: ExpandableTableView, heightForRowAtExpandableIndexPath expandableIndexPath: ExpandableIndexPath) -> CGFloat func expandableTableView(expandableTableView: ExpandableTableView, estimatedHeightForRowAtExpandableIndexPath expandableIndexPath: ExpandableIndexPath) -> CGFloat // Subrows func expandableTableView(expandableTableView: ExpandableTableView, numberOfSubRowsInRowAtExpandableIndexPath expandableIndexPath: ExpandableIndexPath) -> Int func expandableTableView(expandableTableView: ExpandableTableView, subCellForRowAtExpandableIndexPath expandableIndexPath: ExpandableIndexPath) -> UITableViewCell func expandableTableView(expandableTableView: ExpandableTableView, heightForSubRowAtExpandableIndexPath expandableIndexPath: ExpandableIndexPath) -> CGFloat func expandableTableView(expandableTableView: ExpandableTableView, estimatedHeightForSubRowAtExpandableIndexPath expandableIndexPath: ExpandableIndexPath) -> CGFloat
-
Add and implement the ExpandableTableViewDelegate required methods:
// Rows func expandableTableView(expandableTableView: ExpandableTableView, didSelectRowAtExpandableIndexPath expandableIndexPath: ExpandableIndexPath) // Subrows func expandableTableView(expandableTableView: ExpandableTableView, didSelectSubRowAtExpandableIndexPath expandableIndexPath: ExpandableIndexPath)
-
You are done.
In development
Import the following files into your project:
DemoExpandableTableViewController/ExpandableTableViewController folder:
ExpandableTableViewController.swift
ExpandableTableViewDatasource.swift
ExpandableTableViewDelegate.swift
ArrayExtension.swift
enric.macias.lopez, [email protected]
ExpandableTableViewController is available under the MIT license. See the LICENSE file for more info.