测试测试版 | ✗ |
Language语言 | SwiftSwift |
许可证 | MIT |
发布最新发布 | 2017年9月 |
SwiftSwift 版本 | 4.0 |
SPM支持 SPM | ✗ |
由 MangoMade 维护。
从 indexPath 获取静态 cell,
并且这个 cell 将不会被其他 indexPath 的索引重用。
有时我们需要制作类似 设置 的页面。在这个页面中,每一行都有不同的子视图。
不需要创建很多 UITableViewCell
子类或重用 cell。
我们只需要一个带有静态 cell 的表格视图,并将子视图直接添加到 view controller 的实现中。
我们知道,我们可以在 StoryBoard 中创建静态表格视图。
通过代码,我们可以使用这个套件。
当我们要开发一个类似“设置”的页面时,每个 cell 上的子视图都不相同。
从逻辑上我们不需要重用 cell。每一行都创建一个 tableView 的子类又太麻烦。
此时,如果有一个静态表格视图,我们直接在 view controller 的实现中为 cell 添加子视图会更加方便。
在 StoryBoard 中,我们可以直接创建静态表格视图。
通过代码,我们只需要这个套件。
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell: CustomTableViewCell = tableView.sck.dequeueStaticCell(indexPath)
return cell
}
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
guard section == 0 else { return nil }
let header = tableView.sck.dequeueStaticHeaderView(section)
return header
}
func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
guard section == 0 else { return nil }
let footer = tableView.sck.dequeueStaticFooterView(section)
return footer
}
这将分配一个 CustomTableView 类型的 cell。
您无需调用 UITableView.registerClass(_:).
tableView.sck.delegate = self
// `self` may be your view controller which conforming StaticTableViewDelegate.
extension ViewController: StaticTableViewDelegate {
func tableView(_ tableView: UITableView, initStaticCell cell: UITableViewCell, ofIndexPath indexPath: IndexPath) {
}
func tableView(_ tableView: UITableView, initStaticHeader header: UITableViewHeaderFooterView, ofSection section: Int) {
}
func tableView(_ tableView: UITableView, initStaticFooter footer: UITableViewHeaderFooterView, ofSection section: Int) {
}
}
您可以使用 StaticTableViewDelegate
配置 cell 或头部/底部。