1 # JomloTableView
2
3 [![Version](https://img.shields.io/cocoapods/v/JomloTableView.svg?style=flat)](http://cocoapods.org/pods/JomloTableView)
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 [![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fsetoelkahfi%2FJomloTableView%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/setoelkahfi/JomloTableView)
7 [![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fsetoelkahfi%2FJomloTableView%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/setoelkahfi/JomloTableView)
8
9 An iOS UITableView with detachable section and row. Use single section with multiple rows, or multiple sections with multiple rows.
10 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.
11
12 Reference: https://goo.gl/zTGfpi, https://goo.gl/7vMbSF
13
14 ## Example
15
16 To run the example project, clone the repo, and run `pod install` from the Example directory first.
17 ```shell
18 git clone https://github.com/setoelkahfi/JomloTableView
19 cd Example
20 pod install
21 ```
22
23
24 ## Requirements
25
26 iOS 8
27
28 ## Installation
29
30 JomloTableView is available through [CocoaPods](http://cocoapods.org) and Swift Package Manager.
31
32 ### Cocoapods
33 To install
34 it, simply add the following line to your Podfile:
35
36 ```ruby
37 pod "JomloTableView"
38 ```
39
40 ### Swift Package Manager
41
42 ```swift
43
44 ```
45
46 ## Usage
47 ### Simple usage
48 Use single section with multiple rows. All the rows below are from single class.
49 ```swift
50 import UIKit
51 import JomloTableView
52
53 // Another code
54
55 @IBOutlet var jomloTableView: JomloTableView!
56
57 var exampleSection = JomloTableViewSection()
58
59 override func viewDidLoad() {
60 super.viewDidLoad()
61
62 let row0 = SimpleRow("Simple table view", subTitle: "A simple table view like we usually use. But this time, we use JomloTableView.")
63 row0.setOnRowClicked { (row) in
64 self.performSegue(withIdentifier: "showSimpleTableViewExample", sender: self)
65 }
66 exampleSection.addRow(row: row0)
67
68 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.")
69 row1.setOnRowClicked { (row) in
70 self.performSegue(withIdentifier: "showLoadMoreExample", sender: self)
71 }
72 exampleSection.addRow(row: row1)
73
74 // Another rows to add
75
76 jomloTableView.addSection(section: exampleSection)
77 jomloTableView.reloadData()
78
79 }
80
81 // Another code
82 ```
83 The row
84 ```swift
85 import UIKit
86 import JomloTableView
87
88 class SimpleCell: JomloTableViewCell {
89
90 @IBOutlet var titleLabel: UILabel!
91 @IBOutlet var subTitleLabel: UILabel!
92
93 }
94
95 class SimpleRow: JomloTableViewRow {
96
97 var title: String!
98 var subTitle: String!
99
100 init(_ title: String, subTitle: String) {
101 self.title = title
102 self.subTitle = subTitle
103 }
104
105 override var identifier: String {
106 return "SimpleCell"
107 }
108
109 override var rowHeight: CGFloat {
110 return UITableViewAutomaticDimension
111 }
112
113 override var estimatedRowHeight: CGFloat {
114 return 64
115 }
116
117 override func populateView(cell: JomloTableViewCell) {
118 let cell = cell as! SimpleCell
119 cell.titleLabel.text = title
120 cell.subTitleLabel.text = subTitle
121 }
122 }
123
124 ```
125 <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"/>
126
127 ### Load more row
128 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.
129 ```swift
130 import UIKit
131 import JomloTableView
132
133 // Another code
134
135 @IBOutlet var jomloTableView: JomloTableView!
136
137 let tableSection = JomloTableViewSection()
138
139 override func viewDidLoad() {
140 super.viewDidLoad()
141
142 jomloTableView.addSection(section: tableSection)
143 addRows()
144 }
145
146 func addRows() {
147 for _ in 0..<8 {
148 let rowNumber = tableSection.count + 1
149 let row = SimpleRow("Row \(rowNumber)", subTitle: "Example row.")
150 tableSection.addRow(row: row)
151 }
152
153 addLoadMoreRow()
154 }
155
156 func addLoadMoreRow() {
157
158 let loadMoreRow = LoadMoreRow {
159 // To get the effect or loading, delay the execution after 3 seconds
160 DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 3, execute: {
161 self.tableSection.removeLastRow()
162 self.addRows()
163 })
164 }
165
166 tableSection.addRow(row: loadMoreRow)
167 jomloTableView.reloadData()
168 }
169
170 // Another code
171
172 ```
173 <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"/>
174
175 ## Author
176
177 Seto Elkahfi, setoelkahfi@gmail.com
178
179 ## License
180
181 JomloTableView is available under the MIT license. See the LICENSE file for more info.