JExpandableTableView provides out of box support for expandable table cells
To run the example project, clone the repo, and run pod install
from the Example directory first.
App Preview ( Checkout live example app: courtesy Appetize )
- Xcode 8.x
- Swift 3.x
- iOS 8.0
JExpandableTableView is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "JExpandableTableView"
- Expandable cells
- Allows to fetch cells asynchronously (refer tableView(_ tableView: JExpandableTableView, numberOfRowsInSection section: Int, callback: @escaping (Int) -> Void) method in Example)
- Multple configaration for cell expansion and collapse
- Easy integration through xib
- Highly customizable - JExpandableTableView accepts any Header view and Custom cells which makes it very customizable similar to UITableView
Creating instance
- Using interface builder, set class of any UIView to JExpandableTableView & create outlet in respective viewcontroller
@IBOutlet weak var jtableView: JExpandableTableView!
- Using interface builder, set class of any UIView to JExpandableTableView & create outlet in respective viewcontroller
jtableView = JExpandableTableView(frame: <#T##CGRect#>)
Assign delegates, smilar to UITableView delegate
jtableView.delegate = self
jtableView.dataSource = self
Sample delegate methods given below, please refer Example app to get more information.
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
}
If anyone interested in new additions to this repo please feel free to create pull request.
Pramod Jadhav
JExpandableTableView is available under the MIT license. See the LICENSE file for more info.