Coder Social home page Coder Social logo

lnztreeview's Introduction

Build Status codecov Swift

LNZTreeView

This is a swift implementation for iOS of a Tree View. A Tree View is a graphical representation of a tree. Each element (node) can have a number of sub elements (children).

This particular implementation of TreeView organizes nodes and subnodes in rows and each node has an indentation that indicates the hierarchy of the element. A parent can be expanded or collapsed and each children can be a parent itself containing more sub nodes.

LNZTreeView

Basic Principles

The LNZTreeView is a view built on top of UITableView. It proxies UITableView's delegate and datasource in order to have a hierarchical usage of those APIs.

It can work with any entity conforming the protocol TreeNode.

Cells

Just like for UITableView it is possible to use Custom Cells in a LNZTreeView. You can register a cell class to be used for a specific cell Identifier by using the methods register(_ cellClass: AnyClass?, forCellReuseIdentifier identifier: String) and register(_ nib: UINib?, forCellReuseIdentifier identifier: String).

Just like for UITableView it is possible to obtain an UITableViewCell instance of the type previously specified with the register methods by using the dequeueReusableCell(withIdentifier identifier: String, for indexPath: IndexPath) -> UITableViewCell and dequeueReusableCell(withIdentifier identifier: String) -> UITableViewCell? methods.

Delegate and DataSource

The DataSource is the responsible of populating the TreeView according with your set of data. For efficiency, the LNZTreeView will query its data source if needed to get the right info to render the rows. All the indexPaths in the data source's methods are relative to the parameter parentNode.

For example:

root
--- element A
--- --- sub element A
--- --- sub element B
--- --- sub element C
--- element B

In this case an IndexPath with row 1 in parentNode equals to element A, will represent sub element B. The section of IndexPath just like for UITableView represent the index of the section to be rendered. If parentNode is nil, then the indexPath is relative to the root.

Example:

root A
--- element AA
--- --- sub element AA
--- --- sub element AB
--- --- sub element AC
--- element AB
root B

In this case an IndexPath with row 1 in parentNode equals to nil, will represent root B.

All the indexPaths in the delegate works following the same logic.

If selected a node will automatically expand if it is expandable or it will collapse if already expanded. The delegate will be aknowledged of this events by the methods treeView(_ treeView: LNZTreeView, didExpandNodeAt indexPath: IndexPath, forParentNode parentNode: TreeNode?) and treeView(_ treeView: LNZTreeView, didCollapseNodeAt indexPath: IndexPath, forParentNode parentNode: TreeNode?). If the node is not expandable (or collapsable) the method treeView(_ treeView: LNZTreeView, didSelectNodeAt indexPath: IndexPath, forParentNode parentNode: TreeNode?) will be called.

Install

You can install LNZTreeView via cocoapods

use_frameworks!
pod 'LNZTreeView'

lnztreeview's People

Contributors

altagir avatar gringoiredm avatar martinmetselaar avatar

Stargazers

 avatar

Watchers

 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.