Skip to content

Commit

Permalink
Setup as 'TreeView' pod.
Browse files Browse the repository at this point in the history
  • Loading branch information
kernel committed May 23, 2018
1 parent 8e1eb85 commit 504eb58
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 15 deletions.
19 changes: 19 additions & 0 deletions LICENSE
@@ -0,0 +1,19 @@
Copyright © 2018 ReImpl <kernel@reimplement.mobi>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
40 changes: 25 additions & 15 deletions README.md
Expand Up @@ -30,39 +30,49 @@ TreeView adds 2 logical states to every cell: <b>expanded</b> and <b>collapsed</

You should expand cell to reveal its subcells.<br/>
Keeping this in mind helper methods were implemented: <br/>
<i>
- (void)expand:(NSIndexPath *)treeIndexPath;<br/>
- (BOOL)isExpanded:(NSIndexPath *)treeIndexPath;<br/>
- (void)collapse:(NSIndexPath *)treeIndexPath;<br/>
</i>
```objectiveC
- (void)expand:(NSIndexPath *)treeIndexPath;
- (BOOL)isExpanded:(NSIndexPath *)treeIndexPath;
- (void)collapse:(NSIndexPath *)treeIndexPath;
```

Instead of implementing <b>UITableViewDataSource</b> in your controller - change it to <b>TreeTableDataSource</b>. TreeTableDataSource protocol extends UITableViewDataSource by introducing 2 new methods:<br/>
<i>
@required <br/>
- (BOOL)tableView:(UITableView *)tableView isCellExpanded:(NSIndexPath *)treeIndexPath;<br/>
```objectiveC
@required
- (BOOL)tableView:(UITableView *)tableView isCellExpanded:(NSIndexPath *)treeIndexPath;
- (NSUInteger)tableView:(UITableView *)tableView numberOfSubCellsForCellAtIndexPath:(NSIndexPath *)treeIndexPath;
</i>
```

Notice all @required dataSource methods are invoked with indexPath of N-depth that uniquely identify cell or subcell.<br/>
Hence you should change behaviour of the following methods:
<i>
```objectiveC
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)treeIndexPath;
</i>
```

and use
<i>- (NSIndexPath *)tableIndexPathFromTreePath:(NSIndexPath *)treeIndexPath
</i>
```objectiveC
- (NSIndexPath *)tableIndexPathFromTreePath:(NSIndexPath *)treeIndexPath
```
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 such exists) and indexPath parameter is not changed - it is 2d indexPath.
You can convert it into N-depth indexPath with:
<i>
```objectiveC
- (NSIndexPath *)treeIndexPathFromTablePath:(NSIndexPath *)treeIndexPath;
</i>
```
method.


## Installation

TreeView is available through [CocoaPods](http://cocoapods.org/pods/treeview). To install
it, simply add the following line to your Podfile:

```ruby
pod 'TreeView'
```

Conclusion
---

Expand Down
26 changes: 26 additions & 0 deletions TreeView.podspec
@@ -0,0 +1,26 @@
#
# Any lines starting with a # are optional, but their use is encouraged
# To learn more about a Podspec see https://guides.cocoapods.org/syntax/podspec.html
#

Pod::Spec.new do |s|
s.name = 'TreeView'
s.version = '1.1.0'

s.platform = :ios, '8.0'
s.ios.deployment_target = '8.0'
s.requires_arc = true

s.summary = 'TreeView enables cells + subcells in UITableView.'
s.description = <<-DESC
TreeView is a "proxy" object that sits between UITableView and UIViewController,
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, ...).
DESC

s.homepage = 'https://github.com/genkernel/TreeView'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'kernel' => 'kernel@reimplement.mobi' }
s.source = { :git => 'https://github.com/genkernel/TreeView.git', :tag => s.version.to_s }

s.source_files = "TreeTable/*.{h,m}"
end

0 comments on commit 504eb58

Please sign in to comment.