-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathViewController.swift
More file actions
81 lines (68 loc) · 2.7 KB
/
ViewController.swift
File metadata and controls
81 lines (68 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import UIKit
import RefreshControl
import os
fileprivate let logger = Logger(
subsystem: Bundle.main.bundleIdentifier! + ".logger",
category: #file
)
class ViewController: UITableViewController {
enum Section: Int {
case items
}
enum Item: String, CaseIterable {
case refreshControl = "RefreshControl"
case originalRefreshControl = "OriginalRefreshControl"
}
lazy var dataSource = UITableViewDiffableDataSource<Section, Item>(
tableView: tableView,
cellProvider: { [unowned self] (tableView, indexPath, item) in
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
var contentConfiguration = UIListContentConfiguration.cell()
contentConfiguration.text = item.rawValue
cell.contentConfiguration = contentConfiguration
return cell
}
)
var snapshot = NSDiffableDataSourceSnapshot<Section, Item>()
override func viewDidLoad() {
super.viewDidLoad()
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
_ = dataSource
snapshot.appendSections([.items])
snapshot.appendItems(Item.allCases, toSection: .items)
dataSource.apply(snapshot)
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
switch dataSource.itemIdentifier(for: indexPath) {
case .refreshControl:
let vc = RefreshViewController {
let refreshControl = RefreshControl()
refreshControl.timeoverInterval = .seconds(3)
refreshControl.timeoverAttributedTitle = NSAttributedString("Delay. Please wait.")
refreshControl.timeoutInterval = .seconds(10)
refreshControl.onTimeout = { print("Timeout") }
refreshControl.addDelegate(self)
return refreshControl
}
navigationController?.pushViewController(vc, animated: true)
case .originalRefreshControl:
let vc = RefreshViewController {
UIRefreshControl()
}
navigationController?.pushViewController(vc, animated: true)
default:
break
}
}
}
extension ViewController: RefreshControlDelegate {
func didTriggered(_ refreshControl: UIRefreshControl) {
logger.debug("\(#function)")
}
func refreshControl(_ refreshControl: UIRefreshControl, updated revealedFraction: Double) {
logger.debug("\(#function) \(revealedFraction)")
}
func didFinishRefreshing(_ refreshControl: UIRefreshControl) {
logger.debug("\(#function)")
}
}