Advertisement
Guest User

Maio

a guest
Oct 22nd, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. //
  2. // ViewController.swift
  3. // A34-TableView
  4. //
  5. // Created by Marco Bonora on 22/10/2019.
  6. // Copyright © 2019 bonoramarco. All rights reserved.
  7. //
  8.  
  9. import UIKit
  10.  
  11. class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
  12.  
  13. let province:[String]=["Padova","Vicenza","Rovigo","Treviso","Venezia","Belluno","Verona"]
  14. //cell reuse id(la cella che esce dalla vista può essere riutilizzata)
  15. let cellReuseIdentifier="cell"
  16.  
  17. @IBOutlet weak var tbvNome: UITableView!
  18. override func viewDidLoad() {
  19. super.viewDidLoad()
  20. // Do any additional setup after loading the view, typically from a nib.
  21.  
  22. tbvNome.register(UITableViewCell.self, forCellReuseIdentifier: cellReuseIdentifier)
  23. tbvNome.delegate=self
  24. tbvNome.dataSource=self
  25. }
  26.  
  27. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  28. return province.count
  29. }
  30.  
  31. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  32. let cell:UITableViewCell=tbvNome.dequeueReusableCell(withIdentifier:cellReuseIdentifier) as! UITableViewCell
  33.  
  34. cell.textLabel!.text=province[indexPath.row]
  35. cell.imageView?.image=UIImage(named: province[indexPath.row])!
  36. return cell
  37. }
  38.  
  39. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  40. let provincia=province[indexPath.row]
  41. let myUIAlertController1=UIAlertController(title: provincia, message: "Veneto-Italy", preferredStyle: .alert)
  42.  
  43. let myActionOk=UIAlertAction(title: "Ok", style: .cancel, handler: nil)
  44.  
  45. myUIAlertController1.addAction(myActionOk)
  46.  
  47. self.present(myUIAlertController1,animated: true,completion: nil)
  48. }
  49.  
  50.  
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement