TableManager 1.11.0

TableManager 1.11.0

TestsTested
LangLanguage SwiftSwift
License NOASSERTION
ReleasedLast Release Oct 2018
SPMSupports SPM

Maintained by Morbix, Cristian Madrid.



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? -> [email protected]

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.