JExpandableTableView 0.1.1

JExpandableTableView 0.1.1

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布日期最后发布日期2017年6月
SwiftSwift 版本3.0
SPM支持 SPM

Maintained by Pramod Jadhav.



  • By
  • jadhavp

JExpandableTableView

JExpandableTableView 提供了对可展开表格单元格的原生支持

示例

要运行示例项目,先从仓库克隆,然后在 Example 目录中先运行 pod install

应用预览 (检查实时示例应用): 由 Appetize 提供

要求

  • Xcode 8.x
  • Swift 3.x
  • iOS 8.0

安装

JExpandableTableView 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中

pod "JExpandableTableView"

功能

  • 可展开的单元格
  • 允许异步获取单元格(参考示例中的 tableView(_ tableView: JExpandableTableView, numberOfRows section: Int, callback: @escaping (Int) -> Void) 方法)
  • 对单元格展开和折叠的多重配置
  • 易于通过 Xib 集成
  • 高度自定义 - JExpandableTableView 接受任何 Header 视图和自定义单元格,使其可高度自定义,类似于 UITableView

代码集成

创建实例

  • 使用 Interface Builder,将任何 UIView 的类设置为 JExpandableTableView 并在相应的 viewcontroller 中创建 outlets
    @IBOutlet weak var jtableView: JExpandableTableView!
  • 使用 Interface Builder,将任何 UIView 的类设置为 JExpandableTableView 并在相应的 viewcontroller 中创建 outlets
    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);

        })

支持 UIRefreshControl

    jtableView.addRefreshControler(refreshControl: <UIRefreshControl>)

贡献

如果任何人对此仓库的新添加感兴趣,请随时创建 pull 请求。

作者

Pramod Jadhav

许可证

JExpandableTableView遵循MIT许可协议。更多信息请参阅LICENSE文件。