|
1
|
// |
|
2
|
// LoadMoreViewController.swift |
|
3
|
// JomloTableView |
|
4
|
// |
|
5
|
// Created by Seto Elkahfi on 4/8/17. |
|
6
|
// Copyright © 2017 CocoaPods. All rights reserved. |
|
7
|
// |
|
8
|
|
|
9
|
import UIKit |
|
10
|
import JomloTableView |
|
11
|
|
|
12
|
class LoadMoreViewController: UIViewController { |
|
13
|
|
|
14
|
@IBOutlet var jomloTableView: JomloTableView! |
|
15
|
|
|
16
|
let tableSection = JomloTableViewSection() |
|
17
|
|
|
18
|
override func viewDidLoad() { |
|
19
|
super.viewDidLoad() |
|
20
|
|
|
21
|
// Do any additional setup after loading the view. |
|
22
|
|
|
23
|
jomloTableView.addSection(section: tableSection) |
|
24
|
addRows() |
|
25
|
} |
|
26
|
|
|
27
|
override func didReceiveMemoryWarning() { |
|
28
|
super.didReceiveMemoryWarning() |
|
29
|
// Dispose of any resources that can be recreated. |
|
30
|
} |
|
31
|
|
|
32
|
func addRows() { |
|
33
|
for _ in 0..<8 { |
|
34
|
let rowNumber = tableSection.count + 1 |
|
35
|
let row = SimpleRow("Row \(rowNumber)", subTitle: "Example row.") |
|
36
|
tableSection.addRow(row: row) |
|
37
|
} |
|
38
|
|
|
39
|
addLoadMoreRow() |
|
40
|
} |
|
41
|
|
|
42
|
func addLoadMoreRow() { |
|
43
|
|
|
44
|
let loadMoreRow = LoadMoreRow { |
|
45
|
// To get the effect or loading, delay the execution after 3 seconds |
|
46
|
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 3, execute: { |
|
47
|
self.tableSection.removeLastRow() |
|
48
|
self.addRows() |
|
49
|
}) |
|
50
|
} |
|
51
|
|
|
52
|
tableSection.addRow(row: loadMoreRow) |
|
53
|
jomloTableView.reloadData() |
|
54
|
} |
|
55
|
|
|
56
|
} |