-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathViewController.swift
80 lines (54 loc) · 2.09 KB
/
ViewController.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//
// ViewController.swift
// machinetext1(Q1)
//
// Created by Felix ITs 08 on 06/09/19.
// Copyright © 2019 Felix. All rights reserved.
//
import UIKit
var outdoorgame = ["cricket","basketball","hoky","football","kho-kho"]
var element = String()
class ViewController: UIViewController,UITableViewDataSource,UITableViewDelegate{
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let cell = tableView.cellForRow(at: indexPath)
if cell?.accessoryType == .checkmark
{
cell?.accessoryType = .none
}
else
{
cell?.accessoryType = .checkmark
mylabel.text = cell?.textLabel?.text
}
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return outdoorgame.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell(style: .subtitle
, reuseIdentifier: "cell")
cell.textLabel?.text = outdoorgame[indexPath.row]
cell.accessoryType = .none
return cell
}
@IBOutlet var mylabel: UILabel!
@IBAction func press(_ sender: UIButton) {
showalert(title: mylabel.text!, message: mylabel.text! )
}
func showalert(title : String,message: String)
{
let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
let okaction = UIAlertAction(title: "ok", style: .default) { (okaction) in
print("ok is pressed")}
alert.addAction(okaction);
present(alert, animated: true, completion: nil);
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}