SettingsViewController.swift
3.1 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
82
83
84
85
86
87
88
89
//
// SettingsViewController.swift
// InterQR-Internship
//
// Created by Дмитрий Тимофеев on 08.06.2022.
//
import UIKit
class SettingsViewController: UIViewController {
var mainView = SettingsView()
let settingsModel = SettingsModel.allCases
override func loadView() {
view = mainView
}
override func viewDidLoad() {
super.viewDidLoad()
initViewController()
}
private func initViewController() {
mainView.backButton.addTarget(self, action: #selector(didShowHomeVC), for: .touchUpInside)
mainView.logoutButton.addTarget(self, action: #selector(didLogoutAndShowVerificationVC), for: .touchUpInside)
mainView.settingsTableView.registerReusableCell(DisplayNameCell.self)
mainView.settingsTableView.registerReusableCell(SettingsSwitchCell.self)
mainView.settingsTableView.registerReusableCell(SettingsTableViewCell.self)
mainView.settingsTableView.delegate = self
mainView.settingsTableView.dataSource = self
}
}
extension SettingsViewController {
@objc func didShowHomeVC() {
navigationController?.popViewController(animated: true)
}
@objc func didLogoutAndShowVerificationVC() {
let vc = VerificationViewController()
navigationController?.pushViewController(vc, animated: true)
}
}
//MARK: tableView delegate and datasource
extension SettingsViewController: UITableViewDelegate, UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return settingsModel.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let row = indexPath.row
let model: SettingsModel = settingsModel[row]
switch model {
case .displayName:
let cell: DisplayNameCell = tableView.dequeueReusableCell(for: indexPath)
cell.titleLabel.text = model.getTitle()
cell.descriptionLabel.text = model.getDescription()
cell.settingsIcon.image = model.getIcon()
return cell
case .doNotDisturb, .ringtone:
let cell: SettingsSwitchCell = tableView.dequeueReusableCell(for: indexPath)
cell.titleLabel.text = model.getTitle()
cell.descriptionLabel.text = model.getDescription()
cell.settingsIcon.image = model.getIcon()
// cell.delegate = self
return cell
case .editResidents, .widgetLock:
let cell: SettingsTableViewCell = tableView.dequeueReusableCell(for: indexPath)
cell.titleLabel.text = model.getTitle()
cell.descriptionLabel.text = model.getDescription()
cell.settingsIcon.image = model.getIcon()
return cell
}
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if indexPath.row == 3 {
let vc = ChooseApartmentsViewController()
navigationController?.pushViewController(vc, animated: true)
}
}
}