RKTableAdapter
内容
- 需求
- 文档
- 安装
- 使用 TableViewAdapter 与 UITableView
- 使用 CollectionViewAdapter 与 UICollectionView
- 单元模板
- 作者
- 许可协议
- 信息
需求
- iOS 9.0 及以上
- Swift 4.1
文档
最新版本的完整文档可以在 这里 获得
安装
RKTableAdapter 通过 CocoaPods 提供。要安装它,只需在您的 Podfile 中添加以下行
pod 'RKTableAdapter', '~> 0.1'
使用 TableViewAdapter 与 UITableViewDataSource
- 创建单元格和单元格视图模型(示例模板)
- TableViewAdapter 与.ViewController的示例模板
手动创建/更新 ViewController
- 创建 TableViewAdapter
// Create
let tableView: UITableView = UITableView()
lazy var tableAdapter = TableViewAdapter(tableView: self.tableView)
- 如果需要,设置回调
private func setupTableAdapter() {
// tableAdapter.callbacks...
// tableAdapter.scrollViewCallbacks...
}
- 配置内容
private func configureTableAdapterContent() {
let tableList = TableList()
makeMySection(tableList)
tableAdapter.reload(with: tableList)
}
private func makeMySection(_ list: TableList) {
let section = list["mySection"]
section.headerHeight = 30
section.footerHeight = 40
do {
let viewModel = TableSwitchCellVM(title: "Autosave", isOn: true)
vmAutosave.changeAction = autosaveStateChanged
let switchRow = TableRowSwitch(viewModel: vmAutosave)
section.append(row: switchRow)
}
do {
let vm = MenuItemCellVM(title: "Share", action: share)
section.append(row: TableRow<MenuItemCell>(id: "uniq id", viewModel: vm))
}
}
- 添加操作
private lazy var share: TableCellVM.ActionType = { [weak self] userInfo in
guard let sself = self else { return }
// do smth...
}
- 更新 viewDidLoad
override viewDidLoad() {
super.viewDidLoad()
setupTableAdapter()
configureTableAdapterContent()
}
使用 CollectionViewAdapter 与 UICollectionView
- CollectionViewAdapter 与 ViewController的示例模板
- 创建单元格和单元格视图模型(示例模板)
手动创建/更新 ViewController
- 创建 CollectionViewAdapter
// Create
lazy var collectionViewFlow: UICollectionViewFlowLayout = {
let flow = UICollectionViewFlowLayout()
// configure flow layout
return flow
}()
lazy var collectionView: UICollectionView = {
let cv = UICollectionView(frame: .zero, collectionViewLayout: collectionViewFlow)
// configure collection view
return cv
}()
lazy var collectionAdapter = CollectionViewAdapter(collectionView: collectionView)
- 如果需要,设置回调
private func setupCollectionAdapter() {
// collectionAdapter.callbacks...
// collectionAdapter.scrollViewCallbacks...
}
- 配置内容
private func configureCollectionAdapterContent() {
let collectionList = CollectionList()
makeTestSection(collectionList)
collectionAdapter.reload(with: collectionList)
}
private func makeTestSection(_ list: CollectionList) {
let section = list[SectionIds.diary.rawValue]
do {
// let vm = <#Collection Cell VM#>
// vm.action = collectionCellAction
// section.append(row: TableRow<<#Collection Cell Class#>>(id: "uniq id", viewModel: vm))
}
}
- 添加操作
private lazy var collectionCellAction: CollectionCellVM.ActionType = { [weak self] _ in
guard let sself = self else { return }
print("cell taped")
}
- 更新 viewDidLoad
override viewDidLoad() {
super.viewDidLoad()
setupCollectionAdapter()
configureCollectionAdapterContent()
}
模板
使用 Jessica 从模板生成单元格和 ViewController
下载模板
jessica generator pull github.com/daskioff/jessica_templates rk_table_adapter
将 projects.yml 中的 output_paths
修复为您的项目
使用模板
jessica generator gen cell CELL_NAME
or
jessica generator gen cell_calc CELL_NAME
作者
DaskiOFF, [email protected]
许可证
RKTableAdapter 在 MIT 许可证下可用。更多信息请参阅 LICENSE 文件。
依赖项
最后一次构建使用的是在文件 .xcode-version
中指定的 Xcode 版本(了解更多)
最后一次构建使用的是在文件 .swift-version
中指定的 Swift 版本