CocoaPods trunk is moving to be read-only. Read more on the blog, there are 18 months to go.
TestsTested | ✗ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Mar 2016 |
SPMSupports SPM | ✗ |
Maintained by Artur Jaworski.
Pod registers Nibs and allows you to handle all custom UITableViewCells with enum. Written in Swift.
TableViewManager is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "TableViewManager"
Remember about import TableViewManager
.
Create TableViewCellsIdentifiers
enum in your View Controller.
class ViewController: UIViewController {
@IBOutlet weak var tableView: UITableView!
// 1. Cell identifier should be the same as you set in .xib file.
// 2. Every cell should be in separated file named as identifier,
// but you can redefine file name and put multiple cells in one file (see: step 4)
enum TableViewCellsIdentifiers: String {
case TextTableViewCell
case ImageTableViewCell
}
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.delegate = self
self.tableView.dataSource = self
}
}
Implemment tableView(_:cellForRowAtIndexPath:)
as below.
extension ViewController: UITableViewDataSource, UITableViewDelegate {
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
return self.tableViewManager(tableView, cellForRowAtIndexPath: indexPath)
}
// (...)
}
Implemment TableViewManagerProtocol
.
extension ViewController: TableViewManagerProtocol {
// Return cell indentifier for provided indexPath
func tableView(tableView: UITableView, cellIdentifierForIndexPath indexPath: NSIndexPath) -> TableViewCellsIdentifiers {
return .TextTableViewCell
}
// Configure cell as before in tableView(_:cellForRowAtIndexPath:)
func tableView(tableView: UITableView, configureCell cell: UITableViewCell, withCellIdentifier cellIdentifier: TableViewCellsIdentifiers, forIndexPath indexPath: NSIndexPath) {
if let cell = cell as? TextTableViewCell {
cell.myLabel.text = "Lorem Ipsum"
}
}
// Implemment if you want to change default Nib name
//func tableView(tableView: UITableView, nibNameForCellIdentifier cellIdentifier: TableViewCellsIdentifiers) -> String? {
// return nil
//}
}
That’s all!
TableViewManager is available under the MIT license. See the LICENSE file for more info.