forked from glushchenko/fsnotes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProjectListController.swift
62 lines (47 loc) · 1.87 KB
/
ProjectListController.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
//
// ProjectListController.swift
// FSNotes iOS Share Extension
//
// Created by Oleksandr Glushchenko on 12/16/18.
// Copyright © 2018 Oleksandr Glushchenko. All rights reserved.
//
import UIKit
class ProjectListController: UITableViewController {
public weak var delegate: ShareViewController?
public var projects = [Project]()
override func viewDidLoad() {
//title = "Append to"
}
public func setProjects(projects: [Project]) {
self.projects = projects.sorted(by: {
return $0.label < $1.label
})
}
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.projects.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell()
cell.textLabel?.text = self.projects[indexPath.row].label
return cell
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if let cell = tableView.cellForRow(at: indexPath) {
UserDefaultsManagement.lastSelectedURL = projects[indexPath.row].url
cell.accessoryType = .checkmark
let project = self.projects[indexPath.row]
delegate?.loadNotesFrom(project: project)
delegate?.currentProject = self.projects[indexPath.row]
delegate?.projectItem?.value = project.label
self.navigationController?.popViewController(animated: true)
}
}
override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
if delegate?.currentProject == self.projects[indexPath.row] {
cell.accessoryType = .checkmark
}
}
}