created a TableFooterView to be used and refactored ViewController
Signed-off-by: Matt Bruce <mbrucedogs@gmail.com>
This commit is contained in:
parent
aced710388
commit
a0adea163f
@ -14,6 +14,7 @@ class EmployeesViewController: UIViewController {
|
||||
private let modeSegmentedControl = UISegmentedControl(items: EmployeeServiceMode.allCases.map{ $0.rawValue } )
|
||||
private let viewModel = EmployeesViewModel()
|
||||
private var cancellables = Set<AnyCancellable>()
|
||||
private var footerView: TableFooterView?
|
||||
|
||||
public override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
@ -89,10 +90,12 @@ class EmployeesViewController: UIViewController {
|
||||
}
|
||||
|
||||
if let message, !viewModel.isLoading {
|
||||
let footerView = UILabel()
|
||||
footerView.font = .systemFont(ofSize: 17, weight: .medium)
|
||||
footerView.text = message
|
||||
footerView.frame = CGRect(x: 0, y: 0, width: tableView.frame.width, height: 150)
|
||||
// Lazy initialize footerView if needed
|
||||
if footerView == nil {
|
||||
footerView = TableFooterView(message: message)
|
||||
} else { // Update the message
|
||||
footerView?.update(message: message)
|
||||
}
|
||||
tableView.tableFooterView = footerView
|
||||
} else {
|
||||
tableView.tableFooterView = nil
|
||||
|
||||
51
EmployeeDirectory/Views/TableFooterView.swift
Normal file
51
EmployeeDirectory/Views/TableFooterView.swift
Normal file
@ -0,0 +1,51 @@
|
||||
//
|
||||
// EmptyStateFooterView.swift
|
||||
// EmployeeDirectory
|
||||
//
|
||||
// Created by Matt Bruce on 1/20/25.
|
||||
//
|
||||
import UIKit
|
||||
|
||||
public class TableFooterView: UIView {
|
||||
|
||||
/// Label used to show the message
|
||||
private let messageLabel: UILabel = {
|
||||
let label = UILabel()
|
||||
label.textColor = .gray
|
||||
label.textAlignment = .center
|
||||
label.font = UIFont.preferredFont(forTextStyle: .body) // Use a text style for Dynamic Type
|
||||
label.adjustsFontForContentSizeCategory = true // Enable Dynamic Type adjustments
|
||||
label.numberOfLines = 0
|
||||
label.translatesAutoresizingMaskIntoConstraints = false
|
||||
return label
|
||||
}()
|
||||
|
||||
init(message: String) {
|
||||
super.init(frame: .zero)
|
||||
setupUI()
|
||||
update(message: message)
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
/// Setup the UI
|
||||
private func setupUI() {
|
||||
addSubview(messageLabel)
|
||||
NSLayoutConstraint.activate([
|
||||
messageLabel.centerXAnchor.constraint(equalTo: centerXAnchor),
|
||||
messageLabel.centerYAnchor.constraint(equalTo: centerYAnchor),
|
||||
messageLabel.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 16),
|
||||
messageLabel.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -16)
|
||||
])
|
||||
}
|
||||
|
||||
|
||||
/// Updates the Current Message
|
||||
/// - Parameter message: message to show
|
||||
public func update(message: String) {
|
||||
messageLabel.text = message
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user