Latest 0.2.0
Homepage https://github.com/josercc/ZHTableViewGroupSwift
License MIT
Platforms ios 8.0
Authors

ZHTableViewGroup为 UITableView 而生

怎么安装

pod 'ZHTableViewGroupSwift'

怎么使用

  1. 初始化 ZHTableViewDataSource

    var dataSource:ZHTableViewDataSource?
    self.dataSource = ZHTableViewDataSource(tableView: self.tableView)
  2. 初始化 ZHTableViewGroup

    self.dataSource?.addGroup(completionHandle: { (group) in
    //code
    }
  3. 初始化 ZHTableViewCell

    group.addCell(completionHandle: { (cell) in
    //code
    }
  4. 配置 ZHTableViewCell

     cell.anyClass = UITableViewCell.self
     cell.cellNumber = self.cellTexts.count
     cell.identifier = "UITableViewCellIdentifier"
     cell.setConfigCompletionHandle(configCompletionHandle: { (cell, indexPath) in
         let string = self.cellTexts[indexPath.row]
         cell.textLabel?.text = string
         if self.selectTitles.contains(string) {
             cell.accessoryType = .checkmark
         } else {
             cell.accessoryType = .none
         }
     })
     cell.setDidSelectRowCompletionHandle(didSelectRowCompletionHandle: { (cell, indexPath) in
         let string = self.cellTexts[indexPath.row]
         if self.selectTitles.contains(string) {
             guard let index = self.selectTitles.index(of: string) else {
                 return
             }
             self.selectTitles.remove(at: index)
         } else {
             self.selectTitles.append(string)
         }
         self.tableView.reloadData()
     })
  5. 配置 UITableView的代理

       // 设置 UITableView 的组个数
       public override func numberOfSections(in tableView: UITableView) -> Int {
           return ZHTableViewDataSource.numberOfSections(dataSource: self.dataSource)
       }
    
       // 设置组 Cell 的个数
       public override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
           return ZHTableViewDataSource.numberOfRowsInSection(dataSource: self.dataSource, section: section)
       }
    
       // 设置 Cell
       public override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
           let cell = ZHTableViewDataSource.cellForRowAt(dataSource: self.dataSource, indexPath: indexPath)
           cell.selectionStyle = .none
           return cell
       }
    
       public override func  tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
           tableView.deselectRow(at: indexPath, animated: true)
           ZHTableViewDataSource.didSelectRowAt(dataSource: self.dataSource, indexPath: indexPath)
       }

6 清除配置

self.dataSource?.clearData()

Latest podspec

{
    "name": "ZHTableViewGroupSwift",
    "version": "0.2.0",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "summary": "ZHTableViewGroupu4e3a UITableView u800cu751f",
    "homepage": "https://github.com/josercc/ZHTableViewGroupSwift",
    "authors": {
        "josercc": "[email protected]"
    },
    "source": {
        "git": "https://github.com/josercc/ZHTableViewGroupSwift.git",
        "tag": "0.2.0"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "Source/*.swift",
    "resource_bundles": {
        "ZHTableViewGroupSwift": [
            "Resources/**/*.{png}"
        ]
    },
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This