An extension of UITableView. The way it should be. 👍
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Example Bump Oct 17, 2018
Pod/Classes Bump Oct 17, 2018
TableManager.xcodeproj Removing warning with discardableResult attribute Dec 16, 2016
TableManager.xcworkspace convert to Swift 3 Nov 5, 2016
TableManager Added carthage support Aug 11, 2016
TableManagerTests convert to Swift 3 Nov 5, 2016
.gitignore Fix swift version Sep 10, 2018
.travis.yml Update .travis.yml Jun 25, 2016
CHANGELOG.md Update CHANGELOG.md Feb 7, 2017
LICENSE Updated LICENSE Jun 5, 2016
README.md README.md updated due to migration. Oct 17, 2018
TableManager.podspec Bump Oct 17, 2018

README.md

TableManager

Version License Platform Carthage compatible Build Status

TableManager is an extension of UITableView. Manipulate your table in an easier way. Add sections and rows. Configure headers and footers. Hide and show rows individually. And this library will handle all the protocols for you. The table the way it should be.

Requirements

It requires Xcode 10.0 and Swift 4.2.

Your project deployment target must be iOS 8.0+

Installation

CocoaPods

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

pod 'TableManager'

Manually

You can also install it manually just dragging TableManager file to your project.

Basic Usage

Configure the table with only 2 tiny steps

Step 1 - Import TableManager
import TableManager
Step 2 - Add a Row with a configuration
tableView.addRow().setConfiguration { _, cell, _ in 
    cell.textLabel?.text = "Row \(number)"
}

Complete Example

import TableManager

class ViewController: UITableViewController {
    override func viewDidLoad() {
        super.viewDidLoad()

        (1...10).forEach { n in
            tableView.addRow().setConfiguration { _, cell, _ in 
                cell.textLabel?.text = "Row \(n)"
            }    
        }
    }
}

Basic Usage

Documentation

Rows

The magic starts here: adding Rows.

Directly using UITableView's extension
tableView.addRow()
Or instance a row and add it in the table
let someRow = Row()
tableView.addRow(someRow)
You can add a row in a specific section, e.g. the last section
let someRow = Row()
tableView.sections.last?.addRow(someRow)

Visibility

You can change the property visible from any Section and any Row.

someRow.setVisible(true)

someSection.setVisible(false)

Configuring a custom cell

You can set a identifier and the configuration property:

let row = Row(identifier: "CellBasic", object: someString)

row.setConfiguration { (row, cell, indexPath) in
    if let text = row.object as? String {
        cell.textLabel?.text = text
    }
}

tableView.addRow(row)

Or declare a Row.Configuration and attribute it to any row:

let configuration: Row.Configuration = { (row, cell, indexPath) -> Void in
    if let text = row.object as? String {
        cell.textLabel?.text = text
    }
}
let rowA = tableView.addRow(Row(identifier: "CellBasic", object: someObject))
rowA.setConfiguration(configuration)

let rowB = tableView.addRow(Row(identifier: "CellBasic", object: otherObject))
rowB.setConfiguration(configuration)

Row selection event

You can set the didSelect property:

let row = Row(object: someString)

row.setDidSelect { (row, tableView, indexPath) in
    if let text = row.object as? String {
        print(text + " selected")
    }
}

tableView.addRow(row)

Or declare a Row.DidSelect and attribute it to any row:

let didSelect: Row.DidSelect = { (row: Row, tableView: UITableView, indexPath: NSIndexPath) -> Void in
    if let text = row.object as? String {
        print(text + " selected")
    }
}

let rowA = tableView.addRow(Row(object: someString))
rowA.setDidSelect(didSelect)

let rowB = tableView.addRow(Row(object: someString))
rowB.setDidSelect(didSelect)

Selected row

You can get the row that corresponds the selected cell

if let selectedRow = tableView.selectedRow() {
    print('the selected row is: ' + selectedRow.object)
}

Visible rows

You can get the visible rows that corresponds the cells appearing in the UI for the user

if let visibleRows = tableView.visibleRows() {
    visibleRows.forEach { row in
        print(row)
    }
}

UIScrollViewDelegate events

You can handle all the scrollview delegates by your own

class TableViewController: UITableViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
            
        tableView.scrollViewDelegate = self
        
        // [...]
    }
    
    override func scrollViewDidScroll(_ scrollView: UIScrollView) {
        print(scrollView.contentOffset.y)
    }
    
} 

Drag & Drop feature or Reordering

You can make a row draggable when table is editing just passing true in method setCanMove:

let row = tableView.addRow()
            
row.setCanMove(true)

// [...]

tableView.editing = true

Drag and Drop

Deletion

You can make a row deletable when table is editing just passing true in method setCanDelete:

let row = tableView.addRow()
            
row.setCanDelete(true)

// [...]

tableView.editing = true

Deletion

And you can easily edit the title confirmation too:

row.setCanDelete(true, titleForDeleteConfirmation: "Go away")

Go Away

Index Titles

You can make an Index Title(like contacts list on iOS) by just passing the indexTitle for each section that you want to show in indexTitles, calling the method setIndexTitle:

let section = tableView.addSection().setIndexTitle("A")

Index Titles

CHANGELOG

Go to CHANGELOG

Contribute

Feel free to submit your pull request, suggest any update, report a bug or create a feature request.

Just want to say hello? -> morbin_@hotmail.com

Contributors

Author: @Morbin_ / fb.com/hgmorbin

See the people who helps to improve this project: Contributors

License

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