ResidentsViewController.swift 2.46 KB
//
//  ResidentsViewController.swift
//  InterQR-Internship
//
//  Created by Дмитрий Тимофеев on 14.06.2022.
//

import UIKit

class ResidentsViewController: UIViewController {
    var myData: ResidentModel?
    var mainView = ResidentsView()
    var addResidents = AddResidentsViewController()
    override func loadView() {
        view = mainView
    }
    
    override func viewDidLoad() {
        initViewController()
    }
    
    func initViewController() {
        mainView.tableView.delegate = self
        mainView.tableView.dataSource = self
        mainView.tableView.register(ResidentTableViewCell.self, forCellReuseIdentifier: ResidentTableViewCell.id)
        
        mainView.backButton.addTarget(self, action: #selector(didShowChooseApartVC), for: .touchUpInside)
        mainView.addResidentsButton.addTarget(self, action: #selector(willShowAddResidentVC), for: .touchUpInside)
        
        addResidents.delegate = self
        addResidents.didReceiveData()
    }
    
    @objc func didShowChooseApartVC() {
        navigationController?.popViewController(animated: true)
    }
    
    @objc func willShowAddResidentVC() {
//        UIView.animate(withDuration: 0.5) {
//            self.mainView.addResidentView.isHidden = false
//        }
        let vc = AddResidentsViewController()
        vc.modalPresentationStyle = .overCurrentContext
        vc.modalTransitionStyle = .crossDissolve
        present(vc, animated: true)
    }
    
}

//MARK: - TableView delegate & data source
extension ResidentsViewController: UITableViewDelegate, UITableViewDataSource {
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        10
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        guard let cell = tableView.dequeueReusableCell(withIdentifier: ResidentTableViewCell.id, for: indexPath) as? ResidentTableViewCell else { return UITableViewCell() }
//        cell.configureWithItem(doors[indexPath.row])
        cell.serialNumberLabel.text = "\(indexPath.row + 1)"
//        cell.nameLabel.text = myData?.name
//        cell.phoneNumberLabel.text = myData?.mobileNumber
        return cell
    }
}
//MARK: - Protocol delegate
extension ResidentsViewController: ResidentSavable {
    func save(_ data: ResidentModel) {
//        mainView.residentsLabel.text = data.name
        mainView.residentsLabel.reloadInputViews()
        mainView.tableView.reloadData()
    }
}