Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/genkernel/treeview
"TreeView - sub-cells simplified" (c). Enable subcells in UITableView with a single drop-in extension. CocoaPod:
https://github.com/genkernel/treeview
collapsable collapse concept expand expandable expandablelistview expandabletableview indexpath ios nsindexpath objective-c subtree swift tree-node treeview uitableview uitableviewcell uitableviewdatasource
Last synced: 3 months ago
JSON representation
"TreeView - sub-cells simplified" (c). Enable subcells in UITableView with a single drop-in extension. CocoaPod:
- Host: GitHub
- URL: https://github.com/genkernel/treeview
- Owner: genkernel
- License: mit
- Created: 2013-03-16T14:36:12.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2022-10-20T22:40:21.000Z (over 2 years ago)
- Last Synced: 2024-11-20T04:18:10.873Z (3 months ago)
- Topics: collapsable, collapse, concept, expand, expandable, expandablelistview, expandabletableview, indexpath, ios, nsindexpath, objective-c, subtree, swift, tree-node, treeview, uitableview, uitableviewcell, uitableviewdatasource
- Language: Objective-C
- Homepage: http://cocoapods.org/pods/treeview
- Size: 978 KB
- Stars: 54
- Watchers: 3
- Forks: 11
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
**TreeView is iOS single-class component written in ObjC that enables cell + subcells support for UITableView-s.**
- Project status
- Examples
- DocumentationCurrent status
---
TreeView was initially written in 2012 and has been used in multiple projects since then.
Development is finalized, component and its public API is considered stable.The most convenient way to use it is via CocoaPods:
```ruby
pod 'TreeView'
```
Aletrnativelly you may simply drop **TreeView/TreeTable.h,m** into your project.Examples
---
Preview on Youtube: http://youtu.be/zS3gQ4pnmBsYou may find demo iOS app with 3 working modules in _'Examples'_ directory:
- inSwift-4.2
- fileSystem-asTree
- plist-allExpanded-byDefaultDocumentation
---In basic MVC scenario ViewController is set as DataSource of UITableView.
TreeView package introduces single new class: TreeTable.
It is designed to sit in between ViewController and UITableView as a DataSource object that knows how to work with subcells via deeper "nested" indexPaths.TreeTable implements UITableViewDataSource protocol and represents inner subcells with indexPaths of deeper levels. For instance cell at 0-0 indexPath may contain 3 subcells: 0-0-0, 0-0-1, 0-0-2.
In plan MVC example: TreeTable is a "proxy" object that sits between tableView and a viewController, proxies all calls to data source and converts 2d-like indexPaths (0-0, 0-1, ...) into N-depth indexPaths (0-0, 0-0-1, 0-0-2, 0-1-0-1, ...) to represent subcells.
You usually decide to use TreeTable component when your UITableViewCell wants to contain its own subcells that can be easily expanded or collapsed.
Implementation details
---TreeTable adds 2 logical states to every cell: expanded and collapsed.
You should expand a cell to reveal its subcells.
Keeping this in mind helper methods(as UITableView category) were implemented:
```swift
func expand(treeIndexPath: IndexPath)
func isExpanded(treeIndexPath: IndexPath) -> Bool
func collapse(treeIndexPath: IndexPath)
```Instead of implementing UITableViewDataSource in your controller - implement TreeTableDataSource. TreeTableDataSource protocol extends UITableViewDataSource by introducing 2 new required methods:
```swift
func tableView(_ tableView: UITableView, isCellExpandedAt treeIndexPath: IndexPath) -> Bool
func tableView(_ tableView: UITableView, numberOfSubCellsForCellAt treeIndexPath: IndexPath) -> Int
```Notice all required dataSource methods are invoked with indexPath of N-depth that uniquely identify cell or subcell.
Hence you should change behaviour of the following methods:
```swift
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
func tableView(tableView: UITableView, cellForRowAt treeIndexPath: IndexPath) -> UITableViewCell
```and use
```swift
func tableIndexPathFromTreePath(treeIndexPath: IndexPath) -> IndexPath
```
if you need to convert N-depth index path into 2d index path.On the other hand all optional methods are transparently forwarded to your implementations (if you provide any) and indexPath parameter is not changed - it is 2d indexPath.
You can convert it into N-depth treeIndexPath with:
```swift
func treeIndexPathFromTablePath(indexPath: NSIndexPath) -> NSIndexPath
```
method.Concept image
---![Concept](https://github.com/genkernel/TreeView/raw/master/concept.jpg)