StaticTableViewDatasource
概览
快速以编程方式为 iOS 构建静态表格视图
安装
- 通过 Cocoapods
pod StaticTableViewDatasource
说明
- 首先,创建一个 StaticTableViewDatasource 的实例
var datasource = StaticTableViewDatasource()
- 然后,创建一个可选带有标题头和标题尾的节
datasource.addSection("Section Title", footer: "Section Footer") { section in
}
- 对于每个节,你可以通过调用来添加单元格
section.addCell({
let cell = UITableViewCell()
cell.textLabel?.text = "This cell has no action associated with it"
return cell
})
- 您还可以设置单元格被选中时的操作
section.addCell({
let cell = UITableViewCell()
cell.textLabel?.text = "This cell has an action associated with it"
return cell
}, didSelect: {
print("Cell Selected")
})
示例
datasource.addSection(nil) { section in
section.addCell({
let cell = UITableViewCell()
cell.textLabel?.text = "This is the First Cell"
return cell
})
}
datasource.addSection("2nd Section Title", footer: "2nd Section Footer") { section in
section.addCell({
let cell = UITableViewCell()
cell.textLabel?.text = "This cell has no action associated with it"
return cell
})
section.addCell({
let cell = UITableViewCell()
cell.textLabel?.text = "This cell has an action associated with it"
return cell
}, didSelect: {
print("Cell Selected")
})
}