测试测试 | ✗ |
Lang语言 | SwiftSwift |
许可证 | MIT |
发布最新版本 | 2017 年 7 月 |
SwiftSwift 版本 | 3.0 |
SPM支持 SPM | ✗ |
由 LeoMobileDeveloper 维护。
MDTable 是一个 数据驱动的 UITableView。
let row0 = Row(title: "System Cell", accessoryType: .disclosureIndicator)
row0.onDidSelected { (tableView, indexPath) in
tableView.deselectRow(at: indexPath, animated: true)
}
let row1 = Row(title: "Custom Cell", accessoryType: .disclosureIndicator)
let section0 = Section(rows: [row0,row1])
section0.titleForHeader = "Basic"
section0.heightForHeader = 30.0
tableView.manager = TableManager(sections: [section0])
您的 tableView 已经准备好了。
示例项目包含一个 网易云音乐 的示例。(以网易云音乐首页作为示例)
pod "MDTable"
MDTable 提供两种基本类型
Row
- Cell 的模型。Section
- Section 的模型创建行和 Section。
let row = Row(title: "System Cell", accessoryType: .disclosureIndicator)
let section0 = Section(rows: row)
然后使用声明式 API 处理事件
row.onWillDisplay { (tableView, cell, indexPath) in
//Access manager with tableView.manager
}
row.onDidSelected { (tableView, indexPath) in
}
然后创建一个管理器并将其绑定到 tableView
tableManager = TableManager(sections: [section0])
tableView.md_bindTo(manager: tableManager)
创建 ReactiveRow
的子类
class XibRow:ReactiveRow{
//Data
var title:String
var subTitle:String
var image:UIImage
init(title:String, subTitle:String, image:UIImage) {
self.title = title
self.subTitle = subTitle
self.image = image
super.init()
self.rowHeight = 80.0
self.reuseIdentifier = "XibRow"
self.initalType = RowConvertableInitalType.xib(xibName: "CusomCellWithXib")
}
}
创建 MDTableViewCell
的子类,并重写 render
class CusomCellWithXib: MDTableViewCell{
override func render(with row: TableRow) {
guard let row = row as? XibRow else{
return;
}
//Render the cell
}
}
let row = XibRow(title: "Title", subTitle: "Subtitle", image: UIImage(named: "avatar")!)
row.onDidSelected({ (tableView, indexPath) in
tableView.manager?.delete(row: indexPath)
tableView.deleteRows(at: [indexPath], with: .automatic)
})
let section = Section(rows: rows)
section.heightForHeader = 30.0
section.titleForHeader = "Tap Row to Delete"
tableView.manager = TableManager(sections: [section])
您需要使用 [unowned self]
来避免保留循环
row.onDidSelected = { [unowned self] (tableView, indexPath) in
}
Leo, [email protected]
MDTable 在 MIT 许可证下可用。有关更多信息,请参阅 LICENSE 文件。