测试已测试 | ✗ |
语言语言 | SwiftSwift |
许可证 | MIT |
发布日期最后发布日期 | 2017年6月 |
SwiftSwift 版本 | 3.0 |
SPM支持 SPM | ✗ |
Maintained by Pramod Jadhav.
JExpandableTableView 提供了对可展开表格单元格的原生支持
要运行示例项目,先从仓库克隆,然后在 Example 目录中先运行 pod install
。
JExpandableTableView 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中
pod "JExpandableTableView"
创建实例
@IBOutlet weak var jtableView: JExpandableTableView!
jtableView = JExpandableTableView(frame: <#T##CGRect#>)
分配类似 UITableView delegate 的代理
jtableView.delegate = self
jtableView.dataSource = self
以下示例提供的委托方法,请参阅示例应用以获取更多信息。
func tableView(_ tableView: JExpandableTableView, numberOfRowsInSection section: Int, callback: @escaping (Int) -> Void) {
let sectionInfo = self.dataArray[section]
if sectionInfo.cells.count != 0 {
callback(sectionInfo.cells.count)
}else{
tableView.isUserInteractionEnabled = false
SVProgressHUD.show(withStatus: "Loading chapters...")
DispatchQueue.global().async {
Thread.sleep(forTimeInterval: 2)
DispatchQueue.main.sync {
tableView.isUserInteractionEnabled = true
SVProgressHUD.dismiss()
let sectionInfo = self.dataArray[section]
sectionInfo.cells.append(CellInfo("1. Prologue ",cellId: "TextCell"))
sectionInfo.cells.append(CellInfo("2. Bran I",cellId: "TextCell"))
sectionInfo.cells.append(CellInfo("3. Catelyn I",cellId: "TextCell"))
sectionInfo.cells.append(CellInfo("4. Daenerys I",cellId: "TextCell"))
sectionInfo.cells.append(CellInfo("5. A Game of Thrones, very very long chapter beyond the wall",cellId: "TextCell"))
callback(sectionInfo.cells.count)
}
}
}
}
func tableView(_ tableView: JExpandableTableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell{
let section = self.dataArray[indexPath.section]
let row = section.cells[indexPath.row]
let cellId = row.cellId
let cell = tableView.dequeueReusableCell(withIdentifier: cellId!, for: indexPath)
cell.contentView.backgroundColor = UIColor.white
let label = cell.viewWithTag(11) as? UILabel
label?.text = row.text
return cell
}
func numberOfSections(in tableView: JExpandableTableView) -> Int {
return dataArray.count
}
func tableView(_ tableView: JExpandableTableView, viewForHeaderInSection section: Int) -> UIView? {
let section = self.dataArray[section]
let header = tableView.dequeueReusableHeaderFooterView(withIdentifier: "HeaderView")
header?.contentView.backgroundColor = UIColor.groupTableViewBackground
let label = header?.viewWithTag(11) as? UILabel
label?.text = section.title
return header
}
以下代码片段是从示例应用中复制的,展示了此功能
jtableView.openHeader(section: 1);
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(4), execute: {
jtableView.closeHeader(section: 1);
})
jtableView.addRefreshControler(refreshControl: <UIRefreshControl>)
如果任何人对此仓库的新添加感兴趣,请随时创建 pull 请求。
Pramod Jadhav
JExpandableTableView遵循MIT许可协议。更多信息请参阅LICENSE文件。