测试已测试 | ✗ |
Lang语言 | SwiftSwift |
许可证 | MIT |
发布最新版本 | 2016 年 3 月 |
SPM支持 SPM | ✗ |
由 Artur Jaworski 维护。
Pod 注册 Nibs 并允许您使用枚举处理所有自定义 UITableViewCells。用 Swift 编写。
TableViewManager 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中
pod "TableViewManager"
请记住关于 import TableViewManager
。
在您的视图控制器中创建 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
}
}
实现如下 tableView(_:cellForRowAtIndexPath:)
。
extension ViewController: UITableViewDataSource, UITableViewDelegate {
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
return self.tableViewManager(tableView, cellForRowAtIndexPath: indexPath)
}
// (...)
}
实现 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 文件。