TableViewManager 0.2

TableViewManager 0.2

测试已测试
Lang语言 SwiftSwift
许可证 MIT
发布最新版本2016 年 3 月
SPM支持 SPM

Artur Jaworski 维护。



  • Artur Jaworski

TableViewManager

描述

Pod 注册 Nibs 并允许您使用枚举处理所有自定义 UITableViewCells。用 Swift 编写。

安装

TableViewManager 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中

pod "TableViewManager"

快速开始

步骤 1

请记住关于 import TableViewManager

步骤 2

在您的视图控制器中创建 TableViewCellsIdentifiers 枚举。

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
    }
}

步骤 3

实现如下 tableView(_:cellForRowAtIndexPath:)

extension ViewController: UITableViewDataSource, UITableViewDelegate {
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        return self.tableViewManager(tableView, cellForRowAtIndexPath: indexPath)
    }

    // (...)
}

步骤 4

实现 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
    //}
}

就这样!

许可证

TableViewManager 在 MIT 许可证下可用。有关更多信息,请参阅 LICENSE 文件。