回答編集履歴
2
修正
answer
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
`PickerView`の`tag`プロパティで判別すると
|
1
|
+
`PickerView`の`tag`プロパティで判別するのが簡単だと思いますよ。
|
2
2
|
|
3
3
|
```swift
|
4
4
|
import UIKit
|
1
修正
answer
CHANGED
@@ -20,7 +20,7 @@
|
|
20
20
|
|
21
21
|
//pickerView1
|
22
22
|
pickerView1.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.size.width, height: pickerView1.bounds.size.height)
|
23
|
-
pickerView1.tag = 1
|
23
|
+
pickerView1.tag = 1 // <<<<<<<<<< 追加
|
24
24
|
pickerView1.delegate = self
|
25
25
|
pickerView1.dataSource = self
|
26
26
|
|
@@ -43,7 +43,7 @@
|
|
43
43
|
|
44
44
|
//pickerView2
|
45
45
|
pickerView2.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.size.width, height: pickerView2.bounds.size.height)
|
46
|
-
pickerView2.tag = 2
|
46
|
+
pickerView2.tag = 2 // <<<<<<<<<< 追加
|
47
47
|
pickerView2.delegate = self
|
48
48
|
pickerView2.dataSource = self
|
49
49
|
|
@@ -71,7 +71,7 @@
|
|
71
71
|
}
|
72
72
|
|
73
73
|
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
|
74
|
-
if pickerView.tag == 1 {
|
74
|
+
if pickerView.tag == 1 { // <<<<<<<<<< 変更
|
75
75
|
return array1[row]
|
76
76
|
} else {
|
77
77
|
return array2[row]
|
@@ -83,7 +83,7 @@
|
|
83
83
|
}
|
84
84
|
|
85
85
|
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
|
86
|
-
if pickerView.tag == 1 {
|
86
|
+
if pickerView.tag == 1 { // <<<<<<<<<< 変更
|
87
87
|
return array1.count
|
88
88
|
} else {
|
89
89
|
return array2.count
|
@@ -91,7 +91,7 @@
|
|
91
91
|
}
|
92
92
|
|
93
93
|
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
|
94
|
-
if pickerView.tag == 1 {
|
94
|
+
if pickerView.tag == 1 { // <<<<<<<<<< 変更
|
95
95
|
textField1.text = array1[row]
|
96
96
|
} else {
|
97
97
|
textField2.text = array2[row]
|