wuleijun / RJExpandableTableView

RJExpandableTableView is a UITableView subclass that gives you easy access to expandable and collapsable sections by just implementing a few more delegate and dataSource protocols.It is written in Swift.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

RJExpandableTableView

Version License Platform

RJExpandableTableView is a UITableView subclass that gives you easy access to expandable and collapsable sections by just implementing a few more delegate and dataSource protocols. It is written in Swift.

How to use RJExpandableTableView

  • Installation
pod 'RJExpandableTableView'
  • Load the RJExpandableTableView in a UITableViewController
- (void)loadView
{
    self.tableView = [[RJExpandableTableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
}
  • Implement the RJExpandableTableViewDatasource protocol
extension ViewController:RJExpandableTableViewDataSource {
    
    func numberOfSectionsInTableView(tableView: UITableView) -> Int {

        return 10
    }
    
    func tableView(tableView: RJExpandableTableView, canExpandInSection section: Int) -> Bool {
        return true
    }
    
    func tableView(tableView: RJExpandableTableView, needsToDownloadDataForExpandSection section: Int) -> Bool {
        return true
    }
    
    func tableView(tableView: RJExpandableTableView, expandingCellForSection section: Int) -> RJExpandingTableViewCell{
        let expandCell = tableView.dequeueReusableCellWithIdentifier(expandCellId) as! ExpandTableViewCell
        return expandCell
    }
    
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 5
    }
    
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = UITableViewCell(style: .Default, reuseIdentifier: "subCell")
        cell.textLabel?.text = "subcell\(indexPath.section)-\(indexPath.row)"
        cell.backgroundColor = UIColor.lightGrayColor()
        return cell
    }
}
  • Implement the RJExpandableTableViewDelegate protocol
extension ViewController: RJExpandableTableViewDelegate {
    
    func tableView(tableView: RJExpandableTableView, heightForExpandingCellAtSection section: Int) -> CGFloat {
        return 100
    }
    
    func tableView(tableView: RJExpandableTableView, downloadDataForExpandableSection section: Int) {
        //...
    }
}

Sample Screenshots

About

RJExpandableTableView is a UITableView subclass that gives you easy access to expandable and collapsable sections by just implementing a few more delegate and dataSource protocols.It is written in Swift.

License:MIT License


Languages

Language:Swift 94.4%Language:Ruby 5.6%