Git Product home page Git Product logo

pbtreeview's Introduction

PBTreeView

Swift 5.0 iOS License Apache PerfectlySoft Twitter


An UITreeView implementation from UITableView that Apple missed in its UIKit framework. And it is in pure Swift.

★★ Star our github repository to help us! ★★

Created by Partho Biswas (@ParthoBiswas007)

What's in it

  • An UITreeView implementation from UITableView.
  • An iOS application showing it's implementation and usage.

Preview

preview

Requirements

iOS 8.0+ / Swift 5.0+

Setup and Usage

This PBTreeView has been drawn over UITableView. Every row/node of the TreeView represents a UITableViewCell with a custom object.

Step 1:

  • First you need to arrange some datasource that seems like a tree. Check this JSON datasource as example.
  • This JSON data contains RelationshipDetails object as primary unit. This object will contain the information for each node of the tree. This object need to have an unique identifire. In this case, it's social_security_number.

Step 2:

  • Create a TreeViewDataHandler object and call it's following function passing the parsed data array
public func configureTreeViewDatasource(_ relationDetails: [RelationshipDetails]) -> [TreeViewNodeItem]?

And use the return value of the above function as TreeView's data source. Lile following.

var dataHandler: TreeViewDataHandler? = TreeViewDataHandler()
    
let relations: [RelationshipDetails]? = readJson(JSON_File_Name)
var treeViewDataSource = [TreeViewNodeItem]()
treeViewDataSource = (dataHandler?.configureTreeViewDatasource(relations!))!

Step 3:

  • Listen for RelodeTreeView notification to relode the TreeView.
NotificationCenter.default.addObserver(self, selector: #selector(relodeTreeView(_:)), name: NSNotification.Name(rawValue: "RelodeTreeView"), object: nil)

func relodeTreeView(_ notification: Notification) {
  self.treeViewDataSource = (dataHandler?.refreshNodes())!
  DispatchQueue.main.async {
    self.famityTreeTableView.reloadData()
    }
}

Customisation

Setting up UITableViewCell and UITableView

  • Create your own UITableViewCell custom subclass for the TreeView node.

Setting up custom data model

  • Just replace Relations and RelationshipDetails object with your own with proper changes and requirments.

Up Next

  • Dynamic addition and deletion of tree node.
  • Dyanmic Data Container
  • Dynamic View Holder

Contributing

Contributions are welcome. Please just open an Issue on GitHub to discuss a point or request a feature or send a Pull Request with your suggestion. If there's a related discussion on the Swift Evolution mailing list, please also post the thread name with a link.

Please also try to follow the same syntax and semantic in your commit messages (see rationale here).

pbtreeview's People

Contributors

partho-maple avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

pbtreeview's Issues

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.