| 1 | # JomloTableView |
| 2 | |
| 3 | [](http://cocoapods.org/pods/JomloTableView) |
| 4 | [](http://cocoapods.org/pods/JomloTableView) |
| 5 | [](http://cocoapods.org/pods/JomloTableView) |
| 6 | [](https://swiftpackageindex.com/setoelkahfi/JomloTableView) |
| 7 | [](https://swiftpackageindex.com/setoelkahfi/JomloTableView) |
| 8 | |
| 9 | JomloTableView is a `UITableView` helper for building tables out of sections and rows. Use one section with many rows, or several sections with their own rows. |
| 10 | |
| 11 | Writing `UITableViewDelegate` and `UITableViewDataSource` again and again gets old fast. JomloTableView moves that work into the table view itself, so your view controller can hand over sections and rows instead of carrying all the table plumbing. |
| 12 | |
| 13 | ## Example |
| 14 | |
| 15 | To run the example project, clone the repo and install the pods from the `Example` directory: |
| 16 | |
| 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 supports [CocoaPods](http://cocoapods.org) and Swift Package Manager. |
| 31 | |
| 32 | ### CocoaPods |
| 33 | |
| 34 | Add this to your `Podfile`: |
| 35 | |
| 36 | ```ruby |
| 37 | pod "JomloTableView" |
| 38 | ``` |
| 39 | |
| 40 | ### Swift Package Manager |
| 41 | |
| 42 | Add `https://github.com/setoelkahfi/JomloTableView` as a package dependency in Xcode. |
| 43 | |
| 44 | ## Usage |
| 45 | |
| 46 | ### Simple table |
| 47 | |
| 48 | This example uses one section and several rows. Each row below uses the same row class. |
| 49 | |
| 50 | ```swift |
| 51 | import UIKit |
| 52 | import JomloTableView |
| 53 | |
| 54 | // Another code |
| 55 | |
| 56 | @IBOutlet var jomloTableView: JomloTableView! |
| 57 | |
| 58 | var exampleSection = JomloTableViewSection() |
| 59 | |
| 60 | override func viewDidLoad() { |
| 61 | super.viewDidLoad() |
| 62 | |
| 63 | let row0 = SimpleRow("Simple table view", subTitle: "A simple table view like we usually use. But this time, we use JomloTableView.") |
| 64 | row0.setOnRowClicked { (row) in |
| 65 | self.performSegue(withIdentifier: "showSimpleTableViewExample", sender: self) |
| 66 | } |
| 67 | exampleSection.addRow(row: row0) |
| 68 | |
| 69 | 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.") |
| 70 | row1.setOnRowClicked { (row) in |
| 71 | self.performSegue(withIdentifier: "showLoadMoreExample", sender: self) |
| 72 | } |
| 73 | exampleSection.addRow(row: row1) |
| 74 | |
| 75 | // Another rows to add |
| 76 | |
| 77 | jomloTableView.addSection(section: exampleSection) |
| 78 | jomloTableView.reloadData() |
| 79 | |
| 80 | } |
| 81 | |
| 82 | // Another code |
| 83 | ``` |
| 84 | |
| 85 | The row class: |
| 86 | |
| 87 | ```swift |
| 88 | import UIKit |
| 89 | import JomloTableView |
| 90 | |
| 91 | class SimpleCell: JomloTableViewCell { |
| 92 | |
| 93 | @IBOutlet var titleLabel: UILabel! |
| 94 | @IBOutlet var subTitleLabel: UILabel! |
| 95 | |
| 96 | } |
| 97 | |
| 98 | class SimpleRow: JomloTableViewRow { |
| 99 | |
| 100 | var title: String! |
| 101 | var subTitle: String! |
| 102 | |
| 103 | init(_ title: String, subTitle: String) { |
| 104 | self.title = title |
| 105 | self.subTitle = subTitle |
| 106 | } |
| 107 | |
| 108 | override var identifier: String { |
| 109 | return "SimpleCell" |
| 110 | } |
| 111 | |
| 112 | override var rowHeight: CGFloat { |
| 113 | return UITableViewAutomaticDimension |
| 114 | } |
| 115 | |
| 116 | override var estimatedRowHeight: CGFloat { |
| 117 | return 64 |
| 118 | } |
| 119 | |
| 120 | override func populateView(cell: JomloTableViewCell) { |
| 121 | let cell = cell as! SimpleCell |
| 122 | cell.titleLabel.text = title |
| 123 | cell.subTitleLabel.text = subTitle |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | ``` |
| 128 | <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"/> |
| 129 | |
| 130 | ### Load more row |
| 131 | |
| 132 | Add a `loadMoreRow` when you want the table to append more data at the bottom. This example keeps adding rows when the user scrolls to the end, eight rows at a time. |
| 133 | |
| 134 | ```swift |
| 135 | import UIKit |
| 136 | import JomloTableView |
| 137 | |
| 138 | // Another code |
| 139 | |
| 140 | @IBOutlet var jomloTableView: JomloTableView! |
| 141 | |
| 142 | let tableSection = JomloTableViewSection() |
| 143 | |
| 144 | override func viewDidLoad() { |
| 145 | super.viewDidLoad() |
| 146 | |
| 147 | jomloTableView.addSection(section: tableSection) |
| 148 | addRows() |
| 149 | } |
| 150 | |
| 151 | func addRows() { |
| 152 | for _ in 0..<8 { |
| 153 | let rowNumber = tableSection.count + 1 |
| 154 | let row = SimpleRow("Row \(rowNumber)", subTitle: "Example row.") |
| 155 | tableSection.addRow(row: row) |
| 156 | } |
| 157 | |
| 158 | addLoadMoreRow() |
| 159 | } |
| 160 | |
| 161 | func addLoadMoreRow() { |
| 162 | |
| 163 | let loadMoreRow = LoadMoreRow { |
| 164 | // Simulate loading by delaying the next batch for 3 seconds. |
| 165 | DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 3, execute: { |
| 166 | self.tableSection.removeLastRow() |
| 167 | self.addRows() |
| 168 | }) |
| 169 | } |
| 170 | |
| 171 | tableSection.addRow(row: loadMoreRow) |
| 172 | jomloTableView.reloadData() |
| 173 | } |
| 174 | |
| 175 | // Another code |
| 176 | |
| 177 | ``` |
| 178 | <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"/> |
| 179 | |
| 180 | ## Author |
| 181 | |
| 182 | Seto Elkahfi, setoelkahfi@gmail.com |
| 183 | |
| 184 | ## License |
| 185 | |
| 186 | JomloTableView is available under the MIT license. See the LICENSE file for more info. |
| 187 | |
| 188 | ## Copyright |
| 189 | |
| 190 | 2026 Onde Inference (Splitfire AB) |