测试已测试 | ✗ |
语言语言 | SwiftSwift |
许可证 | MIT |
发布最新版本 | 2017年10月 |
SwiftSwift 版本 | 4.0 |
SPM支持 SPM | ✗ |
由 Rob Nash 维护。
Dequable 允许你为你的可重用 UI 组件编写强类型 let 常量,并限制了基于字符串的 cell 标识符的需求。
如果你不使用界面构建器,那么你将不需要声明任何 cell 标识符。
声明合规性。
class TableViewCell: UITableViewCell, DequeableComponentIdentifiable {}
class TableView: UITableView, DequeableTableView {}
如果需要,则注册单元格。
class TableView: UITableView, DequeableTableView {
override init(frame: CGRect, style: UITableViewStyle) {
super.init(frame: frame, style: style)
register(cellType: TableViewCell.self, hasNib: false)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
}
现在你可以解耦强类型的 let 常量。
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell: TableViewCell = (tableView as! DequeableTableView).dequeue(indexPath)
return cell
}
你可能想使用神奇的 Require 框架来锁定你的类型。
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let dequeableTableView: DequeableTableView = (tableView as? DequeableTableView).require(hint: "TableView must conform to DequeableTableView")
let cell: TableViewCell = dequeableTableView.dequeue(indexPath)
return cell
}
如果你使用界面构建器,那么你需要在其中指定单元格标识符。单元格标识符应该是 "Filename"
+ "ID"
。在这个例子中,它将是 "TableViewCellID"
。
假设你的界面构建器文件在同一个包中。所以在这个例子中,如果我们为 TableViewCell 创建了一个界面构建器文件,我们会将它包含在 TableViewCell.swift 文件相同的包中。
如果你喜欢这个,并且想买我一杯饮料,请使用比特币。
比特币地址:15Gj4DBTzSujnJrfRZ6ivrR9kDnWXNPvNQ