Skip to content

Commit 320680f

Browse files
author
kernel
committed
WIP. Moved all examples into master branch and single app. 'inSwift-4.2' example works.
1 parent 0c6dd31 commit 320680f

File tree

25 files changed

+1416
-476
lines changed

25 files changed

+1416
-476
lines changed

DemoArt/demo.gif

-739 KB
Binary file not shown.

Examples/Podfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
platform :ios, '10.0'
2+
3+
target 'TreeViewExample' do
4+
use_frameworks!
5+
6+
pod 'TreeView', :path => '../'
7+
end

TreeViewExample/TreeViewExample/Assets.xcassets/AppIcon.appiconset/Contents.json renamed to Examples/Res/Assets.xcassets/AppIcon.appiconset/Contents.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
{
22
"images" : [
3+
{
4+
"idiom" : "iphone",
5+
"size" : "20x20",
6+
"scale" : "2x"
7+
},
8+
{
9+
"idiom" : "iphone",
10+
"size" : "20x20",
11+
"scale" : "3x"
12+
},
313
{
414
"idiom" : "iphone",
515
"size" : "29x29",
@@ -30,6 +40,16 @@
3040
"size" : "60x60",
3141
"scale" : "3x"
3242
},
43+
{
44+
"idiom" : "ipad",
45+
"size" : "20x20",
46+
"scale" : "1x"
47+
},
48+
{
49+
"idiom" : "ipad",
50+
"size" : "20x20",
51+
"scale" : "2x"
52+
},
3353
{
3454
"idiom" : "ipad",
3555
"size" : "29x29",
@@ -59,6 +79,16 @@
5979
"idiom" : "ipad",
6080
"size" : "76x76",
6181
"scale" : "2x"
82+
},
83+
{
84+
"idiom" : "ipad",
85+
"size" : "83.5x83.5",
86+
"scale" : "2x"
87+
},
88+
{
89+
"idiom" : "ios-marketing",
90+
"size" : "1024x1024",
91+
"scale" : "1x"
6292
}
6393
],
6494
"info" : {
File renamed without changes.

TreeViewExample/TreeViewExample/AppDelegate.swift renamed to Examples/Src/AppDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// AppDelegate.swift
33
// TreeViewExample
44
//
5-
// Created by Altukhov Anton on 07.11.15.
5+
// Created by Anthony on 07.11.15.
66
// Copyright © 2015 ReImpl. All rights reserved.
77
//
88

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14113" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
3+
<device id="retina5_9" orientation="portrait">
4+
<adaptation id="fullscreen"/>
5+
</device>
6+
<dependencies>
7+
<deployment identifier="iOS"/>
8+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14088"/>
9+
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
10+
</dependencies>
11+
<scenes>
12+
<!--View Controller-->
13+
<scene sceneID="EHf-IW-A2E">
14+
<objects>
15+
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
16+
<layoutGuides>
17+
<viewControllerLayoutGuide type="top" id="Llm-lL-Icb"/>
18+
<viewControllerLayoutGuide type="bottom" id="xb3-aO-Qok"/>
19+
</layoutGuides>
20+
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
21+
<rect key="frame" x="0.0" y="0.0" width="375" height="812"/>
22+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
23+
<subviews>
24+
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="TreeView examples app" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontForContentSizeCategory="YES" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="MfF-66-zEA" userLabel="Label">
25+
<rect key="frame" x="56.666666666666657" y="390" width="262" height="32"/>
26+
<fontDescription key="fontDescription" style="UICTFontTextStyleTitle1"/>
27+
<nil key="textColor"/>
28+
<nil key="highlightedColor"/>
29+
</label>
30+
</subviews>
31+
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
32+
<constraints>
33+
<constraint firstItem="MfF-66-zEA" firstAttribute="centerX" secondItem="Ze5-6b-2t3" secondAttribute="centerX" id="Ble-FI-jDr"/>
34+
<constraint firstItem="MfF-66-zEA" firstAttribute="centerY" secondItem="Ze5-6b-2t3" secondAttribute="centerY" id="yCH-Mt-Wys"/>
35+
</constraints>
36+
</view>
37+
</viewController>
38+
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
39+
</objects>
40+
<point key="canvasLocation" x="53" y="375"/>
41+
</scene>
42+
</scenes>
43+
</document>

Examples/Src/UI/Main.storyboard

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14113" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="Y2t-cv-gX2">
3+
<device id="retina5_9" orientation="portrait">
4+
<adaptation id="fullscreen"/>
5+
</device>
6+
<dependencies>
7+
<deployment identifier="iOS"/>
8+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14088"/>
9+
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
10+
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
11+
</dependencies>
12+
<scenes>
13+
<!--Select Controller-->
14+
<scene sceneID="wxS-0Z-nCv">
15+
<objects>
16+
<tableViewController id="Abr-Su-b6m" userLabel="Select Controller" customClass="SelectViewController" customModule="TreeViewExample" customModuleProvider="target" sceneMemberID="viewController">
17+
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" id="Ys6-mB-mvd">
18+
<rect key="frame" x="0.0" y="0.0" width="375" height="812"/>
19+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
20+
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
21+
<prototypes>
22+
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" accessoryType="disclosureIndicator" indentationWidth="10" reuseIdentifier="default" textLabel="MBP-J9-Yo3" style="IBUITableViewCellStyleDefault" id="K57-Ik-1eH">
23+
<rect key="frame" x="0.0" y="28" width="375" height="44"/>
24+
<autoresizingMask key="autoresizingMask"/>
25+
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="K57-Ik-1eH" id="I4x-Qf-GtR">
26+
<rect key="frame" x="0.0" y="0.0" width="341" height="43.666666666666664"/>
27+
<autoresizingMask key="autoresizingMask"/>
28+
<subviews>
29+
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="MBP-J9-Yo3">
30+
<rect key="frame" x="16" y="0.0" width="324" height="43.666666666666664"/>
31+
<autoresizingMask key="autoresizingMask"/>
32+
<fontDescription key="fontDescription" type="system" pointSize="17"/>
33+
<nil key="textColor"/>
34+
<nil key="highlightedColor"/>
35+
</label>
36+
</subviews>
37+
</tableViewCellContentView>
38+
</tableViewCell>
39+
</prototypes>
40+
<connections>
41+
<outlet property="dataSource" destination="Abr-Su-b6m" id="LK0-Ig-Cgr"/>
42+
<outlet property="delegate" destination="Abr-Su-b6m" id="fkS-uA-8YU"/>
43+
</connections>
44+
</tableView>
45+
<navigationItem key="navigationItem" title="Root View Controller" id="5jx-bS-ZkG"/>
46+
<connections>
47+
<segue destination="BYZ-38-t0r" kind="show" identifier="ShowModuleScreen" id="ftB-Xn-6b3"/>
48+
</connections>
49+
</tableViewController>
50+
<placeholder placeholderIdentifier="IBFirstResponder" id="dBY-VT-0ns" userLabel="First Responder" sceneMemberID="firstResponder"/>
51+
</objects>
52+
<point key="canvasLocation" x="-835" y="-268"/>
53+
</scene>
54+
<!--Navigation Controller-->
55+
<scene sceneID="Pbs-hO-spD">
56+
<objects>
57+
<navigationController id="Y2t-cv-gX2" sceneMemberID="viewController">
58+
<navigationBar key="navigationBar" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" id="Dlp-ic-29w">
59+
<rect key="frame" x="0.0" y="44" width="375" height="44"/>
60+
<autoresizingMask key="autoresizingMask"/>
61+
<color key="tintColor" red="1" green="0.57810515169999999" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
62+
</navigationBar>
63+
<connections>
64+
<segue destination="Abr-Su-b6m" kind="relationship" relationship="rootViewController" id="i0X-nu-9Ef"/>
65+
</connections>
66+
</navigationController>
67+
<placeholder placeholderIdentifier="IBFirstResponder" id="VVt-sx-Jfs" userLabel="First Responder" sceneMemberID="firstResponder"/>
68+
</objects>
69+
<point key="canvasLocation" x="-1785" y="-268"/>
70+
</scene>
71+
<!--Table Controller-->
72+
<scene sceneID="tne-QT-ifu">
73+
<objects>
74+
<viewController id="BYZ-38-t0r" userLabel="Table Controller" customClass="TableViewController" customModule="TreeViewExample" customModuleProvider="target" sceneMemberID="viewController">
75+
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
76+
<rect key="frame" x="0.0" y="0.0" width="375" height="812"/>
77+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
78+
<subviews>
79+
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="6sK-XI-Ygt">
80+
<rect key="frame" x="0.0" y="88" width="375" height="690"/>
81+
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
82+
<connections>
83+
<outlet property="dataSource" destination="fAM-jM-SXt" id="KcD-bG-OsN"/>
84+
<outlet property="delegate" destination="BYZ-38-t0r" id="dgF-pD-MBn"/>
85+
</connections>
86+
</tableView>
87+
</subviews>
88+
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
89+
<constraints>
90+
<constraint firstItem="HmU-Jm-VLA" firstAttribute="trailing" secondItem="6sK-XI-Ygt" secondAttribute="trailing" id="SCf-kR-0jX"/>
91+
<constraint firstItem="6sK-XI-Ygt" firstAttribute="top" secondItem="HmU-Jm-VLA" secondAttribute="top" id="ciK-ru-dbz"/>
92+
<constraint firstItem="HmU-Jm-VLA" firstAttribute="bottom" secondItem="6sK-XI-Ygt" secondAttribute="bottom" id="qzE-fl-4ZB"/>
93+
<constraint firstItem="6sK-XI-Ygt" firstAttribute="leading" secondItem="HmU-Jm-VLA" secondAttribute="leading" id="rdz-As-nmw"/>
94+
</constraints>
95+
<viewLayoutGuide key="safeArea" id="HmU-Jm-VLA"/>
96+
</view>
97+
<connections>
98+
<outlet property="tableView" destination="6sK-XI-Ygt" id="gGg-6I-WOs"/>
99+
<outlet property="treeTable" destination="fAM-jM-SXt" id="wk7-dT-kBS"/>
100+
</connections>
101+
</viewController>
102+
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
103+
<customObject id="fAM-jM-SXt" customClass="TreeTable">
104+
<connections>
105+
<outlet property="dataSource" destination="BYZ-38-t0r" id="AqU-x9-FaC"/>
106+
</connections>
107+
</customObject>
108+
</objects>
109+
<point key="canvasLocation" x="145" y="-268"/>
110+
</scene>
111+
</scenes>
112+
</document>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//
2+
// TreeModule.swift
3+
// TreeViewExample
4+
//
5+
// Created by Anthony on 8/21/18.
6+
// Copyright © 2018 ReImpl. All rights reserved.
7+
//
8+
9+
import Foundation
10+
import TreeView
11+
12+
protocol TreeModule: TreeTableDataSource, UITableViewDelegate {
13+
var name: String { get }
14+
15+
func registerCustomCells(with tableView: UITableView)
16+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//
2+
// DAViewController.h
3+
// TreeViewExample
4+
//
5+
// Created by kernel on 13/03/13.
6+
// Copyright (c) 2013 kernel@realm. All rights reserved.
7+
//
8+
9+
#import "TreeTable.h"
10+
11+
@interface DAViewController : UIViewController <UITableViewDelegate>
12+
@property (strong, nonatomic) IBOutlet TreeTable *treeModel;
13+
14+
@property (strong, nonatomic) IBOutlet UITableView *treeView;
15+
@end
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
//
2+
// DAViewController.m
3+
// TreeViewExample
4+
//
5+
// Created by kernel on 13/03/13.
6+
// Copyright (c) 2013 kernel@realm. All rights reserved.
7+
//
8+
9+
#import "DAViewController.h"
10+
11+
static NSString *Subitems = @"Subitems";
12+
static NSString *Title = @"Title";
13+
14+
@interface DAViewController ()
15+
// <indexPath> => @(YES) or nil.
16+
@property (strong, nonatomic, readonly) NSMutableDictionary *expandedItems;
17+
@property (strong, nonatomic, readonly) NSArray *easy;
18+
@end
19+
20+
@implementation DAViewController
21+
22+
- (void)viewDidLoad
23+
{
24+
[super viewDidLoad];
25+
26+
_expandedItems = NSMutableDictionary.dictionary;
27+
28+
NSString *path = [NSBundle.mainBundle pathForResource:@"Easy" ofType:@"plist"];
29+
_easy = [NSArray arrayWithContentsOfFile:path];
30+
31+
Class cls = UITableViewCell.class;
32+
NSString *identifier = NSStringFromClass(cls);
33+
[self.treeView registerClass:cls forCellReuseIdentifier:identifier];
34+
}
35+
36+
- (NSDictionary *)itemForIndexPath:(NSIndexPath *)indexPath {
37+
NSArray *items = self.easy;
38+
NSDictionary *item = self.easy[[indexPath indexAtPosition:0]];
39+
40+
for (int i = 0; i < indexPath.length; i++) {
41+
NSUInteger idx = [indexPath indexAtPosition:i];
42+
43+
item = items[idx];
44+
45+
if (i == indexPath.length - 1) {
46+
return item;
47+
}
48+
49+
items = item[Subitems];
50+
}
51+
52+
return item;
53+
}
54+
55+
#pragma mark TreeTableDataSource
56+
57+
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
58+
return self.easy.count;
59+
}
60+
61+
- (BOOL)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
62+
NSDictionary *item = self.easy[section];
63+
return [item[Subitems] count];
64+
}
65+
66+
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
67+
NSDictionary *item = self.easy[section];
68+
return item[Title];
69+
}
70+
71+
- (BOOL)tableView:(UITableView *)tableView isCellExpanded:(NSIndexPath *)indexPath {
72+
NSDictionary *item = [self itemForIndexPath:indexPath];
73+
74+
NSNumber *initialState = self.expandedItems[indexPath];
75+
BOOL isInitialStateUndefined = !initialState;
76+
77+
if (isInitialStateUndefined && [item isKindOfClass:NSDictionary.class]) {
78+
self.expandedItems[indexPath] = @(YES);
79+
return [item[Subitems] count] > 0;
80+
}
81+
82+
return initialState.boolValue;
83+
}
84+
85+
- (NSUInteger)tableView:(UITableView *)tableView numberOfSubCellsForCellAtIndexPath:(NSIndexPath *)indexPath {
86+
NSDictionary *item = [self itemForIndexPath:indexPath];
87+
return [item[Subitems] count];
88+
}
89+
90+
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
91+
NSDictionary *item = [self itemForIndexPath:indexPath];
92+
93+
NSString *identifier = NSStringFromClass(UITableViewCell.class);
94+
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
95+
96+
cell.indentationLevel = indexPath.length - 1;
97+
98+
NSString *title = nil;
99+
if ([item isKindOfClass:NSDictionary.class]) {
100+
title = item[Title];
101+
102+
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
103+
} else {
104+
title = (NSString *)item;
105+
106+
cell.accessoryType = UITableViewCellAccessoryNone;
107+
}
108+
cell.textLabel.text = title;
109+
110+
// NSLog(@"%@ -> %@", indexPath, title);
111+
return cell;
112+
}
113+
114+
#pragma mark UITableViewDelegate
115+
116+
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)tableIndexPath {
117+
[tableView deselectRowAtIndexPath:tableIndexPath animated:YES];
118+
119+
120+
NSIndexPath *treeIndexPath = [tableView treeIndexPathFromTablePath:tableIndexPath];
121+
122+
BOOL isExpanded = [tableView isExpanded:treeIndexPath];
123+
if (isExpanded) {
124+
self.expandedItems[treeIndexPath] = @(NO);
125+
126+
[tableView collapse:treeIndexPath];
127+
} else {
128+
NSDictionary *item = [self itemForIndexPath:treeIndexPath];
129+
if ([item isKindOfClass:NSString.class]) {
130+
return;
131+
}
132+
133+
self.expandedItems[treeIndexPath] = @(YES);
134+
[tableView expand:treeIndexPath];
135+
}
136+
}
137+
138+
@end

0 commit comments

Comments
 (0)