-
Notifications
You must be signed in to change notification settings - Fork 0
/
DetailTableViewController.swift
59 lines (44 loc) · 1.69 KB
/
DetailTableViewController.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//
// DetailTableViewController.swift
// Day59 - Milestone - Projects 13-14-15
//
// Created by Jean-Yves Garcin on 22/06/2023.
//
import UIKit
class DetailTableViewController: UITableViewController {
var country: Country!
override func viewDidLoad() {
super.viewDidLoad()
title = country.name
let share = UIBarButtonItem(barButtonSystemItem: .action, target: self, action: #selector(shareTapped))
navigationItem.rightBarButtonItems = [share]
}
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 2
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "DetailCell", for: indexPath)
switch indexPath.row {
case 0:
cell.textLabel?.text = "Capital city"
cell.detailTextLabel?.text = country.capitalCity
break
case 1:
cell.textLabel?.text = "Currency"
cell.detailTextLabel?.text = country.currency
break
default:
break
}
return cell
}
@objc func shareTapped() {
let list = "Country: \(country.name)\nCapital City: \(country.capitalCity)\nCurrency: \(country.currency)"
let vc = UIActivityViewController(activityItems: [list], applicationActivities: [])
vc.popoverPresentationController?.barButtonItem = navigationItem.rightBarButtonItem
present(vc, animated: true)
}
}