From 2dc81fcc5937ab5c6baecc993692917f5f220c65 Mon Sep 17 00:00:00 2001 From: Javier Cicchelli Date: Wed, 12 Apr 2023 18:42:07 +0200 Subject: [PATCH] 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. --- .../LocationsListViewController.swift | 23 ++++++++++++++----- .../View Components/LocationViewCell.swift | 2 ++ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/Apps/Locations/Sources/Screens/LocationsList/LocationsListViewController.swift b/Apps/Locations/Sources/Screens/LocationsList/LocationsListViewController.swift index 6410a46..5daf098 100644 --- a/Apps/Locations/Sources/Screens/LocationsList/LocationsListViewController.swift +++ b/Apps/Locations/Sources/Screens/LocationsList/LocationsListViewController.swift @@ -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), diff --git a/Apps/Locations/Sources/View Components/LocationViewCell.swift b/Apps/Locations/Sources/View Components/LocationViewCell.swift index 39a700c..e60875e 100644 --- a/Apps/Locations/Sources/View Components/LocationViewCell.swift +++ b/Apps/Locations/Sources/View Components/LocationViewCell.swift @@ -10,6 +10,8 @@ import UIKit class LocationViewCell: UITableViewCell { + // MARK: Properties + static let identifier = "LocationViewCell" // MARK: Outlets