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