|
1
|
# JomloTableView |
|
2
|
|
|
3
|
[](http://cocoapods.org/pods/JomloTableView) |
|
4
|
[](http://cocoapods.org/pods/JomloTableView) |
|
5
|
[](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
|
|
|
24
|
iOS 8 |
|
25
|
|
|
26
|
## Installation |
|
27
|
|
|
28
|
JomloTableView is available through [CocoaPods](http://cocoapods.org). To install |
|
29
|
it, simply add the following line to your Podfile: |
|
30
|
|
|
31
|
```ruby |
|
32
|
pod "JomloTableView" |
|
33
|
``` |
|
34
|
|
|
35
|
## Usage |
|
36
|
### Simple usage |
|
37
|
Use single section with multiple rows. All the rows below are from single class. |
|
38
|
```swift |
|
39
|
import UIKit |
|
40
|
import JomloTableView |
|
41
|
|
|
42
|
// Another code |
|
43
|
|
|
44
|
@IBOutlet var jomloTableView: JomloTableView! |
|
45
|
|
|
46
|
var exampleSection = JomloTableViewSection() |
|
47
|
|
|
48
|
override func viewDidLoad() { |
|
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 |
|
59
|
self.performSegue(withIdentifier: "showLoadMoreExample", sender: self) |
|
60
|
} |
|
61
|
exampleSection.addRow(row: row1) |
|
62
|
|
|
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
|
|
|
79
|
@IBOutlet var titleLabel: UILabel! |
|
80
|
@IBOutlet var subTitleLabel: UILabel! |
|
81
|
|
|
82
|
} |
|
83
|
|
|
84
|
class SimpleRow: JomloTableViewRow { |
|
85
|
|
|
86
|
var title: String! |
|
87
|
var subTitle: String! |
|
88
|
|
|
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
|
|
|
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
|
``` |
|
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"/> <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 |
|
120
|
import JomloTableView |
|
121
|
|
|
122
|
// Another code |
|
123
|
|
|
124
|
@IBOutlet var jomloTableView: JomloTableView! |
|
125
|
|
|
126
|
let tableSection = JomloTableViewSection() |
|
127
|
|
|
128
|
override func viewDidLoad() { |
|
129
|
super.viewDidLoad() |
|
130
|
|
|
131
|
jomloTableView.addSection(section: tableSection) |
|
132
|
addRows() |
|
133
|
} |
|
134
|
|
|
135
|
func addRows() { |
|
136
|
for _ in 0..<8 { |
|
137
|
let rowNumber = tableSection.count + 1 |
|
138
|
let row = SimpleRow("Row \(rowNumber)", subTitle: "Example row.") |
|
139
|
tableSection.addRow(row: row) |
|
140
|
} |
|
141
|
|
|
142
|
addLoadMoreRow() |
|
143
|
} |
|
144
|
|
|
145
|
func addLoadMoreRow() { |
|
146
|
|
|
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) |
|
156
|
jomloTableView.reloadData() |
|
157
|
} |
|
158
|
|
|
159
|
// Another code |
|
160
|
|
|
161
|
``` |
|
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"/> <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"/> <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
|
|
|
166
|
Seto Elkahfi, setoelkahfi@gmail.com |
|
167
|
|
|
168
|
## License |
|
169
|
|
|
170
|
JomloTableView is available under the MIT license. See the LICENSE file for more info. |