Add non jomlo example and update readme

Seto Elkahfi committed Apr 24, 2017 at 16:07 UTC 82b971e9d8e82b42d410c5e039e63f4820615ef8
2 files changed +72 -31
Example/JomloTableView/View Controllers/NotJomloSimpleTableViewController.swift
+2 -2
@@ -20,7 +20,7 @@ class NotJomloSimpleTableViewController: UIViewController {
20
21 override func viewDidLoad() {
22 super.viewDidLoad()
23 - tableView.isHidden = true
23 +// tableView.isHidden = true
24
25 loginButton = TWTRLogInButton { (session, error) in
26 if let session = session {
@@ -75,7 +75,7 @@ class NotJomloSimpleTableViewController: UIViewController {
75
76 }
77 DispatchQueue.main.async {
78 - tableView.isHidden = false
78 + self.tableView.isHidden = false
79 self.loginButton.removeFromSuperview()
80 self.tableView.reloadData()
81 }
README.md
+70 -29
@@ -4,9 +4,20 @@
4 [![License](https://img.shields.io/cocoapods/l/JomloTableView.svg?style=flat)](http://cocoapods.org/pods/JomloTableView)
5 [![Platform](https://img.shields.io/cocoapods/p/JomloTableView.svg?style=flat)](http://cocoapods.org/pods/JomloTableView)
6
7 +An iOS UITableView with detachable section and row. Use single section with multiple rows, or multiple sections with multiple rows.
8 +Conforming UITableViewDelegate and UITableViewDataSource in every view controller is a mundane and repetitive task. Move the delegate and the data source directly to the table view, and supply the table with section(s) and row(s). Free yourself from Massive-View-Controller.
9 +
10 +Reference: https://goo.gl/zTGfpi, https://goo.gl/7vMbSF
11 +
12 ## Example
13
14 To run the example project, clone the repo, and run `pod install` from the Example directory first.
15 +```shell
16 +git clone https://github.com/setoelkahfi/JomloTableView
17 +cd Example
18 +pod install
19 +```
20 +
21
22 ## Requirements
23
@@ -22,7 +33,7 @@ pod "JomloTableView"
33 ```
34
35 ## Usage
25 -
36 +### Simple usage
37 Use single section with multiple rows. All the rows below are from single class.
38 ```swift
39 import UIKit
@@ -38,39 +49,71 @@ import JomloTableView
49 super.viewDidLoad()
50
51 let row0 = SimpleRow("Simple table view", subTitle: "A simple table view like we usually use. But this time, we use JomloTableView.")
52 + row0.setOnRowClicked { (row) in
53 + self.performSegue(withIdentifier: "showSimpleTableViewExample", sender: self)
54 + }
55 exampleSection.addRow(row: row0)
56
57 let row1 = SimpleRow("Load more", subTitle: "A JomloTableView with load more row at the bottom. Will load infinite row if we scroll the table view to the bottom.")
58 row1.setOnRowClicked { (row) in
45 - self.performSegue(withIdentifier: "showLoadMoreExample", sender: self)
59 + self.performSegue(withIdentifier: "showLoadMoreExample", sender: self)
60 }
61 exampleSection.addRow(row: row1)
62
49 - let row2 = SimpleRow("Dynamic height", subTitle: "Example how to use dynamic height for single row. In fact, this example rows is also use dynamic height.")
50 - exampleSection.addRow(row: row2)
63 + // Another rows to add
64 +
65 + jomloTableView.addSection(section: exampleSection)
66 + jomloTableView.reloadData()
67 +
68 + }
69 +
70 +// Another code
71 +```
72 +The row
73 +```swift
74 +import UIKit
75 +import JomloTableView
76 +
77 +class SimpleCell: JomloTableViewCell {
78
52 - let row3 = SimpleRow("WebView", subTitle: "A JomloTableView with WebView inside of its row.")
53 - exampleSection.addRow(row: row3)
79 + @IBOutlet var titleLabel: UILabel!
80 + @IBOutlet var subTitleLabel: UILabel!
81
55 - let row4 = SimpleRow("Image list", subTitle: "A JomloTableView with image views inside of its row.")
56 - exampleSection.addRow(row: row4)
82 +}
83
58 - let row5 = SimpleRow("Long scrollable layout", subTitle: "A JomloTableView which doesn't look like a table view. ")
59 - exampleSection.addRow(row: row5)
84 +class SimpleRow: JomloTableViewRow {
85
61 - let row6 = SimpleRow("StackView row", subTitle: "A JomloTableView with UIStackView inside of its rows. Here we use UITableViewAutomaticDimension for row's height property.")
62 - exampleSection.addRow(row: row6)
86 + var title: String!
87 + var subTitle: String!
88
64 - jomloTableView.addSection(section: exampleSection)
65 - jomloTableView.reloadData()
89 + init(_ title: String, subTitle: String) {
90 + self.title = title
91 + self.subTitle = subTitle
92 + }
93
94 + override var identifier: String {
95 + return "SimpleCell"
96 }
97
69 -// Another code
98 + override var rowHeight: CGFloat {
99 + return UITableViewAutomaticDimension
100 + }
101 +
102 + override var estimatedRowHeight: CGFloat {
103 + return 64
104 + }
105 +
106 + override func populateView(cell: JomloTableViewCell) {
107 + let cell = cell as! SimpleCell
108 + cell.titleLabel.text = title
109 + cell.subTitleLabel.text = subTitle
110 + }
111 +}
112 +
113 ```
71 -![Example rows 1](/../release-0.2.0/images/example-rows-0.png?raw=true "Example rows 1")
72 -![Example rows 2](/../release-0.2.0/images/example-rows-1.png?raw=true "Example rows 2")
114 +<img src="https://raw.githubusercontent.com/setoelkahfi/JomloTableView/release-0.2.0/images/example-rows-0.png" width="220" height="400" title="Example rows 2"/>&nbsp;&nbsp;&nbsp;<img src="https://raw.githubusercontent.com/setoelkahfi/JomloTableView/release-0.2.0/images/example-rows-1.png" width="220" height="400" title="Example rows 2"/>
115
116 +### Load more row
117 This table view will load more row if loadMoreRow is populated. This example will load infinite rows if user scroll to bottom of table view. Eight rows per each load.
118 ```swift
119 import UIKit
@@ -91,9 +134,9 @@ import JomloTableView
134
135 func addRows() {
136 for _ in 0..<8 {
94 - let rowNumber = tableSection.count + 1
95 - let row = SimpleRow("Row \(rowNumber)", subTitle: "Example row.")
96 - tableSection.addRow(row: row)
137 + let rowNumber = tableSection.count + 1
138 + let row = SimpleRow("Row \(rowNumber)", subTitle: "Example row.")
139 + tableSection.addRow(row: row)
140 }
141
142 addLoadMoreRow()
@@ -101,12 +144,12 @@ import JomloTableView
144
145 func addLoadMoreRow() {
146
104 - let loadMoreRow = LoadMoreRow {
105 - // To get the effect or loading, delay the execution after 3 seconds
106 - DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 3, execute: {
107 - self.tableSection.removeLastRow()
108 - self.addRows()
109 - })
147 + let loadMoreRow = LoadMoreRow {
148 + // To get the effect or loading, delay the execution after 3 seconds
149 + DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 3, execute: {
150 + self.tableSection.removeLastRow()
151 + self.addRows()
152 + })
153 }
154
155 tableSection.addRow(row: loadMoreRow)
@@ -116,9 +159,7 @@ import JomloTableView
159 // Another code
160
161 ```
119 -![Example load more row 1](/../release-0.2.0/images/example-load-more-0.png?raw=true "Example load more row 1")
120 -![Example load more row 2](/../release-0.2.0/images/example-load-more-1.png?raw=true "Example load more row 2")
121 -![Example load more row 3](/../release-0.2.0/images/example-load-more-2.png?raw=true "Example load more row 3")
162 +<img src="https://raw.githubusercontent.com/setoelkahfi/JomloTableView/release-0.2.0/images/example-load-more-0.png" width="220" height="400" title="Example load more rows 1"/>&nbsp;&nbsp;&nbsp;<img src="https://raw.githubusercontent.com/setoelkahfi/JomloTableView/release-0.2.0/images/example-load-more-1.png" width="220" height="400" title="Example load more rows 2"/>&nbsp;&nbsp;&nbsp;<img src="https://raw.githubusercontent.com/setoelkahfi/JomloTableView/release-0.2.0/images/example-load-more-2.png" width="200" height="400" title="Example load more rows 3"/>
163
164 ## Author
165