-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathEndpointListViewController.swift
71 lines (51 loc) · 1.76 KB
/
EndpointListViewController.swift
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
//
// EndpointListViewController.swift
// SoF-MedList
//
// Created by Pascal Pfiffner on 12/3/16.
// Copyright © 2016 SMART Platforms. All rights reserved.
//
import UIKit
import SMART
class EndpointListViewController: UITableViewController {
var endpoints: [Endpoint]?
var onEndpointSelect: ((Endpoint?) -> Void)?
override func viewDidLoad() {
super.viewDidLoad()
self.title = "Endpoints"
self.tableView.register(EndpointCell.self, forCellReuseIdentifier: "Endpoint")
}
// MARK: - UITableViewDataSource
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return endpoints?.count ?? 0
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Endpoint", for: indexPath)
if indexPath.row < endpoints?.count ?? 0 {
let endpoint = endpoints![indexPath.row]
cell.textLabel?.text = endpoint.name ?? "Unnamed"
cell.detailTextLabel?.text = endpoint.client?.server.baseURL.absoluteString
//cell.imageView?.image = UIImage(named: endpoint.name!)
}
return cell
}
// MARK: - UITableViewDelegate
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
guard indexPath.row < endpoints?.count ?? 0 else {
return
}
let endpoint = endpoints![indexPath.row]
onEndpointSelect?(endpoint)
}
}
class EndpointCell: UITableViewCell {
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: .subtitle, reuseIdentifier: reuseIdentifier)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
}