Skip to content
This repository has been archived by the owner on Mar 22, 2024. It is now read-only.
/ melodeon Public archive

A subclass of UITableViewController which behaves like a melodeon.

License

Notifications You must be signed in to change notification settings

chaddgrimm/melodeon

Repository files navigation

Melodeon

Apps Using Downloads Language

CI Status codecov.io Version License Platform

Twitter: @chaddgrimm

A simple subclass of UITableViewController which behaves like a melodeon.

Screen capture

Usage

Inherit MelodeonController and implement it just like you would on a normal UITableViewController.

  class TableViewController: MelodeonController {
    var firstList = ["Option One", "Option Two", "Option Three"]
    var secondList = ["Choice One", "Choice Two", "Choice Three", "Choice Four" ]
    var thirdList = ["Element One", "Element Two"]
   
    ...
    .....
    
  }

Provide your sections as array and override the sections property.

  override var sections:[Any] {
    return ["List A", "List B", "List C"]
  }

And provide the number of rows per section (this is required).

  override func numberOfRows(inSection section:Int) -> Int {
    switch section {
    case 0:
      return firstList.count
    case 1:
      return secondList.count
    case 2:
      return thirdList.count
    default:
      return 0
    }
  }
  

Optional:

You may implement your own header cell as long as it is of type MelodeonHeaderCell.

  override var headerClasses:[MelodeonHeaderCell.Type]? {
    return [TableHeaderCell.self, AnotherHeaderCell.self]
  }

You may also provide the section which will be expanded when the view is loaded.

  override var initialExpandedSection: Int {
    return 0
  }

You can control which header is interactive.

  override func header(_ header: MelodeonHeaderCell, shouldTapAtSection section: Int) -> Bool {
    if section == 1 {
      return false
    }
    return true
  }

Or handle the tap events.

  override func header(_ header: MelodeonHeaderCell, didTapAtSection section: Int) {
    // TODO: Implement header tap event here
  }

Example

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

Requirements

Installation

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

pod "Melodeon"

Author

Chad Lee, chaddgrimm@gmail.com

License

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

About

A subclass of UITableViewController which behaves like a melodeon.

Resources

License

Stars

Watchers

Forks

Packages

No packages published