Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. import UIKit
  2.  
  3. class StationViewController: UIViewController {
  4.  
  5. @IBOutlet weak var tableView: UITableView!
  6.  
  7. var stationProtocol: StationProtocol?
  8. var stations: [Station] = []
  9. var selectedStation: Int = 0
  10.  
  11. override func viewDidLoad() {
  12. super.viewDidLoad()
  13.  
  14. }
  15.  
  16. //MARK: Button back To home.
  17. @IBAction func backToHome_Click(_ sender: Any) {
  18. navigationController?.popViewController(animated: true)
  19. }
  20. }
  21.  
  22. //MARK: Extension data source and delegate.
  23. extension StationViewController: UITableViewDataSource, UITableViewDelegate {
  24.  
  25. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  26. return self.stations.count
  27. }
  28.  
  29. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  30. guard let cell = tableView.dequeueReusableCell(withIdentifier: "stationTableViewCell") as? StationTableViewCell else { return UITableViewCell()}
  31.  
  32. //MARK: Image and name.
  33. if self.selectedStation == indexPath.row {
  34. cell.setDetail(isHidden: false, name: self.stations[indexPath.row].name)
  35. }else {
  36. cell.setDetail(isHidden: true, name: self.stations[indexPath.row].name)
  37. }
  38.  
  39. return cell
  40. }
  41.  
  42. //MARK: didSelectRowAt.
  43. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  44. self.selectedStation = indexPath.row
  45. self.tableView.reloadData()
  46. self.stationProtocol?.setStation(bts: self.stations[indexPath.row])
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement