EZSource
使用方法
-
单元格
应遵从协议ReusableCell
和Configurable
。
final class StringCell: UITableViewCell, ReusableCell, Configurable {
typealias Model = String
func configure(with text: String) {
textLabel?.text = text
}
}
-
源初始化
let source = TableViewDataSource(tableView: tableView, withTypes: [StringCell.self], reusableViews: [])
-
创建行
var row = TableViewRow<StringCell>(model: "My Row")
-
创建TableViewSectionUpdate
TableViewSectionUpdate
提供配置不同章节更新的API,例如动画等。
var updates = TableViewSectionUpdate(sectionID: "\(0)")
updates.addAddOperation(row , at: IndexPath(row: 0, section: 0))
source.applyChanges([updates])
高级用法
给单元格添加滑动操作
-
创建操作
let action = RowAction { [weak self] in
guard let `self` = self else { return }
let alertController = self.alertControllerExample
let act = self.dismissAction(for: alertController)
alertController.addAction(act)
self.present(alertController, animated: true, completion: nil)
}
-
将操作添加到行作为尾随或领先操作
row.addRowLeadingActions([action])
row.addRowTrailingActions([action])
给单元格添加标题和页脚
-
创建一个可重用视图
final class TestReusableView: UITableViewHeaderFooterView, ReusableView, Configurable {
typealias Model = String
func configure(with txt: String) {
label.text = txt
}
}
-
创建页眉/页脚
let header = ImmutableHeaderFooterProvider<TestReusableView>(model: "Section with text labels")
let footer = ImmutableHeaderFooterProvider<TestReusableView>(model: "Footer with text labels")
-
添加页眉/页脚
section.addHeader(header)
section.addFooter(footer)
示例
要运行示例项目,请克隆仓库,然后先从示例目录运行 pod install
。
要求
安装
EZSource 可通过 CocoaPods 获取。要安装它,只需将以下行添加到您的 Podfile
pod 'EZSource'
作者
Swift 大神们,[email protected]
许可协议
EZSource 采用 MIT 许可证。有关更多信息,请参阅 LICENSE 文件。