From 504eb581d3a89c981bbd7bff6123837d11a4cd5d Mon Sep 17 00:00:00 2001 From: kernel Date: Wed, 23 May 2018 12:12:20 -0500 Subject: [PATCH] Setup as 'TreeView' pod. --- LICENSE | 19 +++++++++++++++++++ README.md | 40 +++++++++++++++++++++++++--------------- TreeView.podspec | 26 ++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 15 deletions(-) create mode 100644 LICENSE create mode 100644 TreeView.podspec diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..f0a907d --- /dev/null +++ b/LICENSE @@ -0,0 +1,19 @@ +Copyright © 2018 ReImpl + +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. diff --git a/README.md b/README.md index d00d040..12bdc8b 100644 --- a/README.md +++ b/README.md @@ -30,39 +30,49 @@ TreeView adds 2 logical states to every cell: expanded and collapsed Keeping this in mind helper methods were implemented:
- -- (void)expand:(NSIndexPath *)treeIndexPath;
-- (BOOL)isExpanded:(NSIndexPath *)treeIndexPath;
-- (void)collapse:(NSIndexPath *)treeIndexPath;
-
+```objectiveC +- (void)expand:(NSIndexPath *)treeIndexPath; +- (BOOL)isExpanded:(NSIndexPath *)treeIndexPath; +- (void)collapse:(NSIndexPath *)treeIndexPath; +``` Instead of implementing UITableViewDataSource in your controller - change it to TreeTableDataSource. TreeTableDataSource protocol extends UITableViewDataSource by introducing 2 new methods:
- -@required
-- (BOOL)tableView:(UITableView *)tableView isCellExpanded:(NSIndexPath *)treeIndexPath;
+```objectiveC +@required +- (BOOL)tableView:(UITableView *)tableView isCellExpanded:(NSIndexPath *)treeIndexPath; - (NSUInteger)tableView:(UITableView *)tableView numberOfSubCellsForCellAtIndexPath:(NSIndexPath *)treeIndexPath; -
+``` 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: - +```objectiveC - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section; - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)treeIndexPath; - +``` and use -- (NSIndexPath *)tableIndexPathFromTreePath:(NSIndexPath *)treeIndexPath - +```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: - +```objectiveC - (NSIndexPath *)treeIndexPathFromTablePath:(NSIndexPath *)treeIndexPath; - +``` 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 --- diff --git a/TreeView.podspec b/TreeView.podspec new file mode 100644 index 0000000..db0dfbd --- /dev/null +++ b/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