Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save leoiphonedev/92ac4acb7d1be90157000dbf55c1ec05 to your computer and use it in GitHub Desktop.
Save leoiphonedev/92ac4acb7d1be90157000dbf55c1ec05 to your computer and use it in GitHub Desktop.
Full code implementation of Expandable and collapsable UITableView
//
// ViewController.swift
// ExpandableTable
//
// Created by Aman Aggarwal on 3/21/17.
// Copyright © 2017 iostutorialjunction.com. All rights reserved.
//
import UIKit
class ViewController: UIViewController, ExpandableTableDelegate {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
var dataArray:[Dictionary<String, AnyObject>] = Array()
var indDictionary = [String: AnyObject]()
indDictionary.updateValue("India" as AnyObject, forKey: "parent")
var inCitiesArray:[String] = Array()
inCitiesArray.append("New Delhi")
inCitiesArray.append("Mumbai")
inCitiesArray.append("Chennai")
inCitiesArray.append("Kolkata")
indDictionary.updateValue(inCitiesArray as AnyObject, forKey: "child")
dataArray.append(indDictionary)
var usaDictionary = [String: AnyObject]()
usaDictionary.updateValue("USA" as AnyObject, forKey: "parent")
var usCitiesArray:[String] = Array()
usCitiesArray.append("New York")
usCitiesArray.append("Chicago")
usCitiesArray.append("Dellas")
usCitiesArray.append("Vegas")
usaDictionary.updateValue(usCitiesArray as AnyObject, forKey: "child")
dataArray.append(usaDictionary)
var ukDictionary = [String: AnyObject]()
ukDictionary.updateValue("United Kindom" as AnyObject, forKey: "parent")
var ukCitiesArray:[String] = Array()
ukCitiesArray.append("London")
ukCitiesArray.append("Lancashire")
ukCitiesArray.append("Manchestar")
ukCitiesArray.append("NewCastle")
ukDictionary.updateValue(ukCitiesArray as AnyObject, forKey: "child")
dataArray.append(ukDictionary)
var saDictionary = [String: AnyObject]()
saDictionary.updateValue("Australia" as AnyObject, forKey: "parent")
var saCitiesArray:[String] = Array()
saCitiesArray.append("Sydney")
saCitiesArray.append("Canberra")
saCitiesArray.append("Melbourne")
saCitiesArray.append("Perth")
saDictionary.updateValue(saCitiesArray as AnyObject, forKey: "child")
dataArray.append(saDictionary)
let expandableTable = ExpandableTable(nibName: "ExpandableTable", bundle: nil)
expandableTable.dataSourceForPlainTable = dataArray
expandableTable.view.frame = CGRect(x: 0, y: 20, width: UIScreen.main.bounds.size.width, height: UIScreen.main.bounds.size.height-20)
expandableTable.delegate = self
self.view.addSubview(expandableTable.view)
self.addChildViewController(expandableTable)
expandableTable.tblExpandable.reloadData()
}
//MARK:- ExpandedCell Delegate
func valueSelected(value: AnyObject) {
print("selection ==", value as! String)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment