Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // ViewController.swift
- // A34-TableView
- //
- // Created by Marco Bonora on 22/10/2019.
- // Copyright © 2019 bonoramarco. All rights reserved.
- //
- import UIKit
- class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
- let province:[String]=["Padova","Vicenza","Rovigo","Treviso","Venezia","Belluno","Verona"]
- //cell reuse id(la cella che esce dalla vista può essere riutilizzata)
- let cellReuseIdentifier="cell"
- @IBOutlet weak var tbvNome: UITableView!
- override func viewDidLoad() {
- super.viewDidLoad()
- // Do any additional setup after loading the view, typically from a nib.
- tbvNome.register(UITableViewCell.self, forCellReuseIdentifier: cellReuseIdentifier)
- tbvNome.delegate=self
- tbvNome.dataSource=self
- }
- func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- return province.count
- }
- func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- let cell:UITableViewCell=tbvNome.dequeueReusableCell(withIdentifier:cellReuseIdentifier) as! UITableViewCell
- cell.textLabel!.text=province[indexPath.row]
- cell.imageView?.image=UIImage(named: province[indexPath.row])!
- return cell
- }
- func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
- let provincia=province[indexPath.row]
- let myUIAlertController1=UIAlertController(title: provincia, message: "Veneto-Italy", preferredStyle: .alert)
- let myActionOk=UIAlertAction(title: "Ok", style: .cancel, handler: nil)
- myUIAlertController1.addAction(myActionOk)
- self.present(myUIAlertController1,animated: true,completion: nil)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement