测试已测试 | ✗ |
语言语言 | SwiftSwift |
许可证 | MIT |
发布最后发布 | 2017 年 1 月 |
SwiftSwift 版本 | 3.0 |
SPM支持 SPM | ✗ |
由 Fernando Ortiz 维护。
DequeuableRegistrable 是一组简单的协议扩展,允许在不使用不安全的字符串或显式转换的情况下注册和排队单元格以及页脚/页眉(从 UITableView 或 UICollectionView)。
要运行示例项目,请克隆 repo,然后首先从 Example 目录运行 pod install
DequeuableRegistrable 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile
pod "DequeuableRegistrable", :git => "https://github.com/fmo91/DequeuableRegistrable/"
DequeuableRegistrable 将注册从这样变得容易
tableView.register(UINib(nibName: "DogCell", bundle: nil), forCellReuseIdentifier: "DogCell")
到这样
DogCell.register(in: tableView)
排队也这样简单
let cell = tableView.dequeueReusableCell(withIdentifier: "DogCell") as! DogCell
到这样
let cell = DogCell.dequeue(from: tableView)
// cell is DogCell, not UITableViewCell. It's already casted.
唯一需要做的是这样
extension DogCell: Registrable, Dequeuable {}
DequeuableRegistrable 包含三个简单的协议
Identifiable
:它允许通过提供键字符串来识别任何类型的对象。对于单元格,该字符串是可重用标识符。Dequeuable
:继承自 Identifiable
。它允许使用 Identifiable
协议提供的可重用标识符从 UICollectionView
或 UITableView
排队单元格。Registrable
:继承自 Identifiable
。它允许使用 Identifiable
协议提供的可重用标识符和在 Registrable
协议中要求的 nib 对象在 UICollectionView
或 UITableView
中注册单元格。所有这些协议都有扩展,返回与类名匹配的默认值。因此,例如,如果您有一个 ABCCell
类,那么其默认可重用标识符将是 "ABCCell"
,其 UINib
将是 UINib(nibName: "ABCCell")
Fernando Ortiz,[email protected]
DequeuableRegistrable 在 MIT 许可证下可用。有关更多信息,请参阅 LICENSE 文件。