Conformed the LocationsListViewController view controller to the UITableViewDataSource and the UITableViewDelegate protocols.
This commit is contained in:
parent
ea9fea98b3
commit
51e4c64a11
@ -25,6 +25,8 @@ class LocationsListViewController: BaseViewController {
|
|||||||
private lazy var table = {
|
private lazy var table = {
|
||||||
let table = UITableView(frame: .zero, style: .plain)
|
let table = UITableView(frame: .zero, style: .plain)
|
||||||
|
|
||||||
|
table.dataSource = self
|
||||||
|
table.delegate = self
|
||||||
table.translatesAutoresizingMaskIntoConstraints = false
|
table.translatesAutoresizingMaskIntoConstraints = false
|
||||||
|
|
||||||
return table
|
return table
|
||||||
@ -50,10 +52,47 @@ class LocationsListViewController: BaseViewController {
|
|||||||
setupBar()
|
setupBar()
|
||||||
setupView()
|
setupView()
|
||||||
bindViewModel()
|
bindViewModel()
|
||||||
|
|
||||||
|
viewModel.loadLocations()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - UITableViewDataSource
|
||||||
|
|
||||||
|
extension LocationsListViewController: UITableViewDataSource {
|
||||||
|
|
||||||
|
// MARK: Functions
|
||||||
|
|
||||||
|
func numberOfSections(in tableView: UITableView) -> Int {
|
||||||
|
viewModel.numberOfSectionsInData
|
||||||
|
}
|
||||||
|
|
||||||
|
func tableView(
|
||||||
|
_ tableView: UITableView,
|
||||||
|
numberOfRowsInSection section: Int
|
||||||
|
) -> Int {
|
||||||
|
viewModel.numberOfDataItems(in: section)
|
||||||
|
}
|
||||||
|
|
||||||
|
func tableView(
|
||||||
|
_ tableView: UITableView,
|
||||||
|
cellForRowAt indexPath: IndexPath
|
||||||
|
) -> UITableViewCell {
|
||||||
|
let cell = tableView.dequeueReusableCell(withIdentifier: "cellID", for: indexPath)
|
||||||
|
let entity = viewModel.dataItem(at: indexPath)
|
||||||
|
|
||||||
|
cell.textLabel?.text = entity.name
|
||||||
|
|
||||||
|
return cell
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - UITableViewDelegate
|
||||||
|
|
||||||
|
extension LocationsListViewController: UITableViewDelegate {}
|
||||||
|
|
||||||
// MARK: - Helpers
|
// MARK: - Helpers
|
||||||
|
|
||||||
private extension LocationsListViewController {
|
private extension LocationsListViewController {
|
||||||
@ -76,7 +115,13 @@ private extension LocationsListViewController {
|
|||||||
view.addSubview(table)
|
view.addSubview(table)
|
||||||
view.addSubview(error)
|
view.addSubview(error)
|
||||||
view.addSubview(loading)
|
view.addSubview(loading)
|
||||||
error.onRetry = { print("RETRY BUTTON PRESSED!") }
|
|
||||||
|
error.onRetry = {
|
||||||
|
self.viewModel.loadLocations()
|
||||||
|
}
|
||||||
|
|
||||||
|
table.register(UITableViewCell.self, forCellReuseIdentifier: "cellID")
|
||||||
|
|
||||||
NSLayoutConstraint.activate([
|
NSLayoutConstraint.activate([
|
||||||
error.widthAnchor.constraint(equalToConstant: 300),
|
error.widthAnchor.constraint(equalToConstant: 300),
|
||||||
view.centerXAnchor.constraint(equalTo: error.centerXAnchor),
|
view.centerXAnchor.constraint(equalTo: error.centerXAnchor),
|
||||||
@ -99,6 +144,10 @@ private extension LocationsListViewController {
|
|||||||
self.error.isHidden = viewStatus != .error
|
self.error.isHidden = viewStatus != .error
|
||||||
self.loading.isHidden = viewStatus != .loading
|
self.loading.isHidden = viewStatus != .loading
|
||||||
self.table.isHidden = viewStatus != .loaded
|
self.table.isHidden = viewStatus != .loaded
|
||||||
|
|
||||||
|
if viewStatus == .loaded {
|
||||||
|
self.table.reloadData()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.store(in: &cancellables)
|
.store(in: &cancellables)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user