Load more example offline done.
Seto Elkahfi committed
Apr 8, 2017 at 18:36 UTC
c3485aaabd8cbaf4d8053afcd3e0d12a892c006e
7 files changed
+77
-23
Example/JomloTableView/Base.lproj/Main.storyboard
+4
-1
@@ -34,7 +34,7 @@
34
<scene sceneID="xtz-2B-VF9">
35
<objects>
36
<viewController title="Load More Example" id="g32-7R-g4E" customClass="LoadMoreViewController" customModule="JomloTableView_Example" customModuleProvider="target" sceneMemberID="viewController">
37
- <tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="28" sectionFooterHeight="28" id="rYm-wF-070">
37
+ <tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="28" sectionFooterHeight="28" id="rYm-wF-070" customClass="JomloTableView" customModule="JomloTableView">
38
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
39
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
40
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
@@ -42,6 +42,9 @@
42
<navigationItem key="navigationItem" title="LoadMore" id="7yA-oT-lrA">
43
<barButtonItem key="backBarButtonItem" title="Back" id="qOO-5C-71O"/>
44
</navigationItem>
45
+ <connections>
46
+ <outlet property="jomloTableView" destination="rYm-wF-070" id="qJc-up-AiO"/>
47
+ </connections>
48
</viewController>
49
<placeholder placeholderIdentifier="IBFirstResponder" id="DKX-6f-sJi" userLabel="First Responder" sceneMemberID="firstResponder"/>
50
</objects>
Example/JomloTableView/LoadMoreViewController.swift
+31
-10
@@ -2,18 +2,26 @@
2
// LoadMoreViewController.swift
3
// JomloTableView
4
//
5
-// Created by SDMobile on 4/8/17.
5
+// Created by Seto Elkahfi on 4/8/17.
6
// Copyright © 2017 CocoaPods. All rights reserved.
7
//
8
9
import UIKit
10
+import JomloTableView
11
12
class LoadMoreViewController: UIViewController {
13
+
14
+ @IBOutlet var jomloTableView: JomloTableView!
15
+
16
+ let tableSection = JomloTableViewSection()
17
18
override func viewDidLoad() {
19
super.viewDidLoad()
20
21
// Do any additional setup after loading the view.
22
+
23
+ jomloTableView.addSection(section: tableSection)
24
+ addRows()
25
}
26
27
override func didReceiveMemoryWarning() {
@@ -21,15 +29,28 @@ class LoadMoreViewController: UIViewController {
29
// Dispose of any resources that can be recreated.
30
}
31
24
-
25
- /*
26
- // MARK: - Navigation
27
-
28
- // In a storyboard-based application, you will often want to do a little preparation before navigation
29
- override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
30
- // Get the new view controller using segue.destinationViewController.
31
- // Pass the selected object to the new view controller.
32
+ func addRows() {
33
+ for _ in 0..<8 {
34
+ let rowNumber = tableSection.count + 1
35
+ let row = SimpleRow("Row \(rowNumber)", subTitle: "Example row.")
36
+ tableSection.addRow(row: row)
37
+ }
38
+
39
+ addLoadMoreRow()
40
+ }
41
+
42
+ func addLoadMoreRow() {
43
+
44
+ let loadMoreRow = LoadMoreRow {
45
+ // To get the effect or loading, delay the execution after 3 seconds
46
+ DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 3, execute: {
47
+ self.tableSection.removeLastRow()
48
+ self.addRows()
49
+ })
50
+ }
51
+
52
+ tableSection.addRow(row: loadMoreRow)
53
+ jomloTableView.reloadData()
54
}
33
- */
55
56
}
Example/JomloTableView/Rows/LoadMoreCell.swift
+1
-1
@@ -11,6 +11,6 @@ import JomloTableView
11
12
class LoadMoreCell: JomloTableViewCell {
13
14
-
14
+ @IBOutlet var activityIndicator: UIActivityIndicatorView!
15
16
}
Example/JomloTableView/Rows/LoadMoreCell.xib
+9
-6
@@ -11,15 +11,15 @@
11
<objects>
12
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
13
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
14
- <tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="LoadMoreCell" rowHeight="58" id="KGk-i7-Jjw" customClass="LoadMoreCell" customModule="JomloTableView_Example" customModuleProvider="target">
15
- <rect key="frame" x="0.0" y="0.0" width="432" height="58"/>
14
+ <tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="LoadMoreCell" rowHeight="87" id="KGk-i7-Jjw" customClass="LoadMoreCell" customModule="JomloTableView_Example" customModuleProvider="target">
15
+ <rect key="frame" x="0.0" y="0.0" width="453" height="87"/>
16
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
17
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="KGk-i7-Jjw" id="H2p-sc-9uM">
18
- <rect key="frame" x="0.0" y="0.0" width="432" height="58"/>
18
+ <rect key="frame" x="0.0" y="0.0" width="453" height="87"/>
19
<autoresizingMask key="autoresizingMask"/>
20
<subviews>
21
- <activityIndicatorView opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" style="gray" translatesAutoresizingMaskIntoConstraints="NO" id="wXd-bK-aYS">
22
- <rect key="frame" x="206" y="19" width="20" height="20"/>
21
+ <activityIndicatorView opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" animating="YES" style="gray" translatesAutoresizingMaskIntoConstraints="NO" id="wXd-bK-aYS">
22
+ <rect key="frame" x="217" y="34" width="20" height="20"/>
23
</activityIndicatorView>
24
</subviews>
25
<constraints>
@@ -27,7 +27,10 @@
27
<constraint firstItem="wXd-bK-aYS" firstAttribute="centerY" secondItem="H2p-sc-9uM" secondAttribute="centerY" id="z5V-UT-IqR"/>
28
</constraints>
29
</tableViewCellContentView>
30
- <point key="canvasLocation" x="82" y="59"/>
30
+ <connections>
31
+ <outlet property="activityIndicator" destination="wXd-bK-aYS" id="OMN-IU-Nep"/>
32
+ </connections>
33
+ <point key="canvasLocation" x="92.5" y="73.5"/>
34
</tableViewCell>
35
</objects>
36
</document>
Example/JomloTableView/Rows/LoadMoreRow.swift
+19
-2
@@ -2,7 +2,7 @@
2
// LoadMoreRow.swift
3
// JomloTableView
4
//
5
-// Created by SDMobile on 4/5/17.
5
+// Created by Seto Elkahfi on 4/5/17.
6
// Copyright © 2017 CocoaPods. All rights reserved.
7
//
8
@@ -11,11 +11,28 @@ import JomloTableView
11
12
class LoadMoreRow: JomloTableViewRow {
13
14
+ internal var onLoadMore: (() -> Void)!
15
+
16
+ init(_ onLoadMore: @escaping ()->Void) {
17
+ self.onLoadMore = onLoadMore
18
+ }
19
+
20
+ override var identifier: String {
21
+ return "LoadMoreCell"
22
+ }
23
24
override var rowHeight: CGFloat {
16
- return 62
25
+ return 44
26
}
27
28
+ override var estimatedRowHeight: CGFloat {
29
+ return 44
30
+ }
31
32
+ override func populateView(cell: JomloTableViewCell) {
33
+ let cell = cell as! LoadMoreCell
34
+ cell.activityIndicator.startAnimating()
35
+ onLoadMore()
36
+ }
37
38
}
Example/JomloTableView/Rows/SimpleCell.xib
+3
-3
@@ -15,17 +15,17 @@
15
<rect key="frame" x="0.0" y="0.0" width="598" height="120"/>
16
<autoresizingMask key="autoresizingMask"/>
17
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="Jxp-d1-zT1" id="150-Wq-GWr">
18
- <rect key="frame" x="0.0" y="0.0" width="598" height="119.5"/>
18
+ <rect key="frame" x="0.0" y="0.0" width="598" height="120"/>
19
<autoresizingMask key="autoresizingMask"/>
20
<subviews>
21
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="252" text="Title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="fUm-db-ewC" userLabel="Title">
22
- <rect key="frame" x="8" y="8" width="582" height="19.5"/>
22
+ <rect key="frame" x="8" y="8" width="582" height="20"/>
23
<fontDescription key="fontDescription" type="boldSystem" pointSize="16"/>
24
<nil key="textColor"/>
25
<nil key="highlightedColor"/>
26
</label>
27
<label opaque="NO" userInteractionEnabled="NO" contentMode="top" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Multi line explanation" textAlignment="justified" lineBreakMode="tailTruncation" numberOfLines="4" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="c4C-y0-zNM" userLabel="Sub title">
28
- <rect key="frame" x="8" y="27.5" width="582" height="84"/>
28
+ <rect key="frame" x="8" y="28" width="582" height="84"/>
29
<fontDescription key="fontDescription" type="italicSystem" pointSize="14"/>
30
<color key="textColor" red="0.50196081400000003" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
31
<nil key="highlightedColor"/>
JomloTableView/Classes/JomloTableViewSection.swift
+10
@@ -41,4 +41,14 @@ public class JomloTableViewSection {
41
self.rows.removeAll()
42
}
43
44
+ // Remove last row in this table view section
45
+ public func removeLastRow() {
46
+ self.rows.removeLast()
47
+ }
48
+
49
+ // Remove first row in this table view section
50
+ public func removeFirstRow() {
51
+ self.rows.removeFirst()
52
+ }
53
+
54
}