Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import UIKit
- class StationViewController: UIViewController {
- @IBOutlet weak var tableView: UITableView!
- var stationProtocol: StationProtocol?
- var stations: [Station] = []
- var selectedStation: Int = 0
- override func viewDidLoad() {
- super.viewDidLoad()
- }
- //MARK: Button back To home.
- @IBAction func backToHome_Click(_ sender: Any) {
- navigationController?.popViewController(animated: true)
- }
- }
- //MARK: Extension data source and delegate.
- extension StationViewController: UITableViewDataSource, UITableViewDelegate {
- func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- return self.stations.count
- }
- func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- guard let cell = tableView.dequeueReusableCell(withIdentifier: "stationTableViewCell") as? StationTableViewCell else { return UITableViewCell()}
- //MARK: Image and name.
- if self.selectedStation == indexPath.row {
- cell.setDetail(isHidden: false, name: self.stations[indexPath.row].name)
- }else {
- cell.setDetail(isHidden: true, name: self.stations[indexPath.row].name)
- }
- return cell
- }
- //MARK: didSelectRowAt.
- func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
- self.selectedStation = indexPath.row
- self.tableView.reloadData()
- self.stationProtocol?.setStation(bts: self.stations[indexPath.row])
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement