質問編集履歴
1
該当のソースコード
test
CHANGED
File without changes
|
test
CHANGED
@@ -20,9 +20,77 @@
|
|
20
20
|
|
21
21
|
```
|
22
22
|
|
23
|
+
import UIKit
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
class ViewController: UIViewController,UIPickerViewDelegate, UIPickerViewDataSource {
|
28
|
+
|
29
|
+
@IBOutlet weak var mylabel: UILabel!
|
30
|
+
|
31
|
+
@IBOutlet weak var mytextfeild: UITextField!
|
32
|
+
|
33
|
+
@IBOutlet weak var picker: UIPickerView!
|
34
|
+
|
35
|
+
let array = ["item1","item2","item3","item4"]
|
36
|
+
|
37
|
+
override func viewDidLoad() {
|
38
|
+
|
39
|
+
super.viewDidLoad()
|
40
|
+
|
41
|
+
// Do any additional setup after loading the view.
|
42
|
+
|
43
|
+
self.picker.delegate = self
|
44
|
+
|
45
|
+
self.picker.dataSource = self
|
46
|
+
|
47
|
+
mylabel.text = "hoge"
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
}
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
//pickerに列数を渡す
|
58
|
+
|
59
|
+
func numberOfComponents(in pickerView: UIPickerView) -> Int {
|
60
|
+
|
61
|
+
return 1 }
|
62
|
+
|
63
|
+
//pickerに行数を返す
|
64
|
+
|
65
|
+
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
|
66
|
+
|
67
|
+
return array.count
|
68
|
+
|
69
|
+
}
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
|
74
|
+
|
75
|
+
return array[row]
|
76
|
+
|
77
|
+
}
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
|
82
|
+
|
23
|
-
func pickerView(_pickerView: UIPickerView, didSelectRow row: Int, forComponent component: Int) {
|
83
|
+
func pickerView(_pickerView: UIPickerView, didSelectRow row: Int, forComponent component: Int) {
|
24
84
|
|
25
85
|
self.mylabel.text = String(array[row])
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
}
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
}
|
26
94
|
|
27
95
|
```
|
28
96
|
|