-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathViewController.swift
More file actions
72 lines (57 loc) · 2.28 KB
/
ViewController.swift
File metadata and controls
72 lines (57 loc) · 2.28 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
//
// Validator
// Copyright © 2025 Space Code. All rights reserved.
//
import UIKit
import ValidatorCore
import ValidatorUI
// MARK: - ViewController
final class ViewController: UIViewController {
private let examples: [ExampleItem] = [
ExampleItem(title: "UITextField Example", controller: LoginTextFieldExampleViewController()),
ExampleItem(title: "UITextView Example", controller: FeedbackTextViewExampleViewController()),
]
private let tableView = UITableView(frame: .zero, style: .insetGrouped)
override func viewDidLoad() {
super.viewDidLoad()
title = "Examples"
view.backgroundColor = .systemBackground
setupTableView()
}
private func setupTableView() {
tableView.dataSource = self
tableView.delegate = self
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
tableView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(tableView)
NSLayoutConstraint.activate([
tableView.topAnchor.constraint(equalTo: view.topAnchor),
tableView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
tableView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
tableView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
])
}
}
// MARK: UITableViewDataSource, UITableViewDelegate
extension ViewController: UITableViewDataSource, UITableViewDelegate {
func tableView(_: UITableView, numberOfRowsInSection _: Int) -> Int {
examples.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
let example = examples[indexPath.row]
cell.textLabel?.text = example.title
cell.accessoryType = .disclosureIndicator
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
let example = examples[indexPath.row]
navigationController?.pushViewController(example.controller, animated: true)
}
}
// MARK: - ExampleItem
struct ExampleItem {
let title: String
let controller: UIViewController
}