Coder Social home page Coder Social logo

amjadalsawafta / expandabletableviewcontroller Goto Github PK

View Code? Open in Web Editor NEW

This project forked from enricmacias/expandabletableviewcontroller

0.0 2.0 0.0 3.21 MB

Swift library to easily show, hide and customize table view cells as an expandable list of items.

License: MIT License

Swift 62.12% Ruby 3.94% Objective-C 2.21% Shell 31.73%

expandabletableviewcontroller's Introduction

ExpandableTableViewController

Version License Platform

Description

Swift library to easily show, hide and customize table view cells as an expandable list of items.

alt tag

Requirements

  • iOS 8.0
  • UIKit

In detail

An ExpandableTableView is a normal UITableView, but with subrows under its rows. If a normal UITableView has sections and rows, an ExpandableTableView has sections, rows and subrows.

Usage

1.Implement your UITableViewController class with the ExpandableTableViewController class and ExpandableTableViewDelegate protocol.

class DemoTableViewController: ExpandableTableViewController, ExpandableTableViewDelegate {
	...
}

2.In your Storyboard, set the UITableView object with the ExpandableTableView class.

3.In your Storyboard, connect the IBOutlet expandableTableView with your current UITableView object.

4.Set the expandableDatasource and expandableDelegate properties to self in your viewDidLoad()

override func viewDidLoad() {
	super.viewDidLoad()

	self.expandableTableView.expandableDelegate = self
}

5.Add and implement the ExpandableTableViewDelegate required methods:

// Rows
func expandableTableView(expandableTableView: ExpandableTableView, numberOfRowsInSection section: Int) -> Int
func expandableTableView(expandableTableView: ExpandableTableView, cellForRowAtExpandableIndexPath expandableIndexPath: ExpandableIndexPath) -> UITableViewCell
func expandableTableView(expandableTableView: ExpandableTableView, heightForRowAtExpandableIndexPath expandableIndexPath: ExpandableIndexPath) -> CGFloat
func expandableTableView(expandableTableView: ExpandableTableView, estimatedHeightForRowAtExpandableIndexPath expandableIndexPath: ExpandableIndexPath) -> CGFloat
func expandableTableView(expandableTableView: ExpandableTableView, didSelectRowAtExpandableIndexPath expandableIndexPath: ExpandableIndexPath)

// Subrows
func expandableTableView(expandableTableView: ExpandableTableView, numberOfSubRowsInRowAtExpandableIndexPath expandableIndexPath: ExpandableIndexPath) -> Int
func expandableTableView(expandableTableView: ExpandableTableView, subCellForRowAtExpandableIndexPath expandableIndexPath: ExpandableIndexPath) -> UITableViewCell
func expandableTableView(expandableTableView: ExpandableTableView, heightForSubRowAtExpandableIndexPath expandableIndexPath: ExpandableIndexPath) -> CGFloat
func expandableTableView(expandableTableView: ExpandableTableView, estimatedHeightForSubRowAtExpandableIndexPath expandableIndexPath: ExpandableIndexPath) -> CGFloat
func expandableTableView(expandableTableView: ExpandableTableView, didSelectSubRowAtExpandableIndexPath expandableIndexPath: ExpandableIndexPath)

*Use the "dequeueReusableCellWithIdentifier(identifier:, expandableIndexPath:)" method from the expandableTableView property to deque cells with the given ExpandableIndexPath.

func expandableTableView(expandableTableView: ExpandableTableView, cellForRowAtExpandableIndexPath expandableIndexPath: ExpandableIndexPath) -> UITableViewCell
{
    let cell = expandableTableView.dequeueReusableCellWithIdentifier("CellIdentifier", forIndexPath: expandableIndexPath)

    return cell
}

Useful methods

//////////// * ExpandableTableView Methods * ////////////
// Returns the cell at the ExpandableIndexPath given.
public func cellForRowAtIndexPath(expandableIndexPath: ExpandableIndexPath) -> UITableViewCell?

// Deques a cell a the ExpandableIndexPath given.
public func dequeueReusableCellWithIdentifier(identifier: String, forIndexPath expandableIndexPath: ExpandableIndexPath) -> UITableViewCell

// Shows if the ExpandableIndexPath provided is an expanded cell or not.
public func isCellExpandedAtExpandableIndexPath(expandableIndexPath:ExpandableIndexPath) -> Bool

// Deselects the cell at the ExpandableIndexPath given.
public func deselectRowAtExpandableIndexPath(expandableIndexPath: ExpandableIndexPath, animated: Bool)

//////////// * ExpandableTableViewController Methods * ////////////
// Unexpands all the expanded cells at once.
public func unexpandAllCells()

Installation

Cocoapods

pod "ExpandableTableViewController"

Manually

Import the following files into your project:

ExpandableTableViewController/ExpandableTableViewController/Classes folder:

ExpandableTableViewController.swift
ExpandableTableViewDelegate.swift
ArrayExtension.swift

Author

enric.macias.lopez, [email protected]

License

ExpandableTableViewController is available under the MIT license. See the LICENSE file for more info.

expandabletableviewcontroller's People

Contributors

amjadalsawafta avatar enricmacias avatar genadyo avatar glpgs-kike avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.