/
sberpay
/
AgeGate-iOS
Обзор
Документация
Войти
/
sberpay
/
AgeGate-iOS
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
develop
AgeGateExample/Presentation/ConfigModule/ConfigVC.swift
130 строк
4 KB
SergeyGladkiy
[0.2.0] БДСЧ сценарий
30 июл 2026, 21:57
30 июл 2026, 21:57
cbcdfcb
Код
Авторство
О чём код?
// // ConfigVC.swift // SberPay // // Created by Alexander Ipatov on 07.11.2022. // import UIKit protocol ConfigVCProtocol: AnyObject { func reload() func reloadSection(_ section: Int) func showAlert(title: String, message: String?) func showSelectableAlert(title: String, items: [String], selected: @escaping (Int) -> Void) func push(_ viewController: UIViewController) } final class ConfigVC: UIViewController, ConfigVCProtocol { private let presenter: ConfigPresenterProtocol private lazy var tableView: UITableView = { let view = UITableView(frame: .zero, style: .insetGrouped) view.register(SwitchCell.self, forCellReuseIdentifier: String(describing: SwitchCell.self)) view.register(SegmentedControlCell.self, forCellReuseIdentifier: String(describing: SegmentedControlCell.self)) view.register(TextViewCell.self, forCellReuseIdentifier: String(describing: TextViewCell.self)) view.register(ListCell.self, forCellReuseIdentifier: String(describing: ListCell.self)) view.register(ButtonCell.self, forCellReuseIdentifier: String(describing: ButtonCell.self)) view.dataSource = self view.delegate = self view.keyboardDismissMode = .interactive view.translatesAutoresizingMaskIntoConstraints = false return view }() init(presenter: ConfigPresenterProtocol) { self.presenter = presenter super.init(nibName: nil, bundle: nil) } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } override func viewDidLoad() { super.viewDidLoad() title = "Настройки" view.backgroundColor = .systemGroupedBackground setupUI() presenter.viewDidLoad() } private func setupUI() { 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: - ConfigVCProtocol func reload() { tableView.reloadData() } func reloadSection(_ section: Int) { tableView.reloadSections([section], with: .fade) } func showAlert(title: String, message: String?) { let alert = UIAlertController(title: title, message: message, preferredStyle: .alert) alert.addAction(.init(title: "Понятно", style: .default)) present(alert, animated: true) } func showSelectableAlert(title: String, items: [String], selected: @escaping (Int) -> Void) { let alert = UIAlertController(title: title, message: nil, preferredStyle: .actionSheet) items.enumerated().forEach { index, item in alert.addAction(.init(title: item, style: .default) { _ in selected(index) }) } alert.addAction(.init(title: "Отмена", style: .cancel)) alert.popoverPresentationController?.sourceView = view present(alert, animated: true) } func push(_ viewController: UIViewController) { navigationController?.pushViewController(viewController, animated: true) } } // MARK: - UITableViewDataSource extension ConfigVC: UITableViewDataSource { func numberOfSections(in tableView: UITableView) -> Int { presenter.sectionCount } func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { presenter.numberOfRows(in: section) } func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { presenter.title(for: section) } func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? { presenter.footer(for: section) } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { presenter.cell(for: indexPath, in: tableView) } } // MARK: - UITableViewDelegate extension ConfigVC: UITableViewDelegate { func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { tableView.deselectRow(at: indexPath, animated: true) presenter.didSelectRow(at: indexPath) } }