Registered the LocationViewCell with the "table" outlet in the LocationsListViewController view controller and updated its "tableView(_: cellForRowAt: )" function to use and update the mentioned cell.

This commit is contained in:
Javier Cicchelli 2023-04-12 18:42:07 +02:00
parent 63f476157f
commit 2dc81fcc59
2 changed files with 19 additions and 6 deletions

View File

@ -29,6 +29,8 @@ class LocationsListViewController: BaseViewController {
table.delegate = self
table.translatesAutoresizingMaskIntoConstraints = false
table.register(LocationViewCell.self, forCellReuseIdentifier: LocationViewCell.identifier)
return table
}()
@ -79,11 +81,22 @@ extension LocationsListViewController: UITableViewDataSource {
_ tableView: UITableView,
cellForRowAt indexPath: IndexPath
) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cellID", for: indexPath)
guard let cell = tableView.dequeueReusableCell(
withIdentifier: LocationViewCell.identifier,
for: indexPath
) as? LocationViewCell else {
return .init()
}
let entity = viewModel.dataItem(at: indexPath)
cell.textLabel?.text = entity.name
cell.update(
iconName: entity.source == .remote ? "network" : "house",
name: entity.name,
latitude: entity.latitude,
longitude: entity.longitude
)
return cell
}
@ -119,9 +132,7 @@ private extension LocationsListViewController {
error.onRetry = {
self.viewModel.loadLocations()
}
table.register(UITableViewCell.self, forCellReuseIdentifier: "cellID")
NSLayoutConstraint.activate([
error.widthAnchor.constraint(equalToConstant: 300),
view.centerXAnchor.constraint(equalTo: error.centerXAnchor),

View File

@ -10,6 +10,8 @@ import UIKit
class LocationViewCell: UITableViewCell {
// MARK: Properties
static let identifier = "LocationViewCell"
// MARK: Outlets