質問編集履歴

3

ソースコードの更新

2016/07/21 05:12

投稿

M.minoru
M.minoru

スコア19

test CHANGED
File without changes
test CHANGED
@@ -96,7 +96,7 @@
96
96
 
97
97
 
98
98
 
99
- if koutsuusyudan.tag == 1{
99
+ if pickerView.tag == 1{
100
100
 
101
101
  return koutsuuList.count
102
102
 
@@ -114,7 +114,7 @@
114
114
 
115
115
 
116
116
 
117
- if koutsuusyudan.tag == 1{
117
+ if pickerView.tag == 1{
118
118
 
119
119
  return koutsuuList[row]
120
120
 
@@ -134,7 +134,7 @@
134
134
 
135
135
 
136
136
 
137
- if koutsuusyudan.tag == 1{
137
+ if pickerView.tag == 1{
138
138
 
139
139
  koutsuusyudan.text = self.koutsuuList[row]
140
140
 

2

ソースコードの更新

2016/07/21 05:12

投稿

M.minoru
M.minoru

スコア19

test CHANGED
File without changes
test CHANGED
@@ -50,12 +50,6 @@
50
50
 
51
51
  // Do any additional setup after loading the view, typically from a nib.
52
52
 
53
-
54
-
55
- let picketView = UIPickerView()
56
-
57
- picketView.tag = 1
58
-
59
53
 
60
54
 
61
55
  kubun.selectorPicker.delegate = self
@@ -65,6 +59,12 @@
65
59
  koutsuusyudan.selectorPicker.delegate = self
66
60
 
67
61
  koutsuusyudan.selectorPicker.dataSource = self
62
+
63
+
64
+
65
+ kubun.tag = 0
66
+
67
+ koutsuusyudan.tag = 1
68
68
 
69
69
  }
70
70
 
@@ -94,9 +94,9 @@
94
94
 
95
95
  func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
96
96
 
97
+
97
98
 
98
-
99
- if pickerView.tag == 1{
99
+ if koutsuusyudan.tag == 1{
100
100
 
101
101
  return koutsuuList.count
102
102
 
@@ -112,9 +112,9 @@
112
112
 
113
113
  func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
114
114
 
115
+
115
116
 
116
-
117
- if pickerView.tag == 1{
117
+ if koutsuusyudan.tag == 1{
118
118
 
119
119
  return koutsuuList[row]
120
120
 
@@ -132,17 +132,17 @@
132
132
 
133
133
  func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
134
134
 
135
+
135
136
 
137
+ if koutsuusyudan.tag == 1{
136
138
 
137
- if pickerView.tag == 1{
138
-
139
- koutsuusyudan.text = self.koutsuuList[row]
139
+ koutsuusyudan.text = self.koutsuuList[row]
140
140
 
141
141
  }
142
142
 
143
143
  else{
144
144
 
145
- kubun.text = self.kubunList[row]
145
+ kubun.text = self.kubunList[row]
146
146
 
147
147
  }
148
148
 

1

コードの追加

2016/07/21 03:59

投稿

M.minoru
M.minoru

スコア19

test CHANGED
File without changes
test CHANGED
@@ -11,3 +11,153 @@
11
11
  そこでStoryboardにPickerViewを貼り付けた時にプロパティで設定できるTagを、
12
12
 
13
13
  コードを書いて作ったPickerViewで設定するにはどのように記述すれば良いのでしょうか。
14
+
15
+
16
+
17
+
18
+
19
+ #####ソースコード
20
+
21
+ ```
22
+
23
+ import UIKit
24
+
25
+
26
+
27
+ class InputKotsu: UIViewController, UITextFieldDelegate, UIPickerViewDataSource, UIPickerViewDelegate {
28
+
29
+
30
+
31
+ let kubunList = ["交通費(通勤)", "交通費", "宿泊","日当"]
32
+
33
+ let youkenList = ["定期", "営業", "その他"]
34
+
35
+ let koutsuuList = ["電車","バス", "タクシー", "飛行機","船舶"]
36
+
37
+ let oufukuList = ["往復", "片道"]
38
+
39
+
40
+
41
+ @IBOutlet weak var kubun: SubPicker!
42
+
43
+ @IBOutlet weak var koutsuusyudan: SubPicker!
44
+
45
+
46
+
47
+ override func viewDidLoad() {
48
+
49
+ super.viewDidLoad()
50
+
51
+ // Do any additional setup after loading the view, typically from a nib.
52
+
53
+
54
+
55
+ let picketView = UIPickerView()
56
+
57
+ picketView.tag = 1
58
+
59
+
60
+
61
+ kubun.selectorPicker.delegate = self
62
+
63
+ kubun.selectorPicker.dataSource = self
64
+
65
+ koutsuusyudan.selectorPicker.delegate = self
66
+
67
+ koutsuusyudan.selectorPicker.dataSource = self
68
+
69
+ }
70
+
71
+
72
+
73
+ override func didReceiveMemoryWarning() {
74
+
75
+ super.didReceiveMemoryWarning()
76
+
77
+ // Dispose of any resources that can be recreated.
78
+
79
+ }
80
+
81
+
82
+
83
+ // 項目の数
84
+
85
+ func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
86
+
87
+ return 1
88
+
89
+ }
90
+
91
+
92
+
93
+ // 要素数
94
+
95
+ func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
96
+
97
+
98
+
99
+ if pickerView.tag == 1{
100
+
101
+ return koutsuuList.count
102
+
103
+ }
104
+
105
+ return self.kubunList.count
106
+
107
+ }
108
+
109
+
110
+
111
+ //要素を表す文字列
112
+
113
+ func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
114
+
115
+
116
+
117
+ if pickerView.tag == 1{
118
+
119
+ return koutsuuList[row]
120
+
121
+ }
122
+
123
+
124
+
125
+ return self.kubunList[row]
126
+
127
+ }
128
+
129
+
130
+
131
+ //テキストフィールドに表示
132
+
133
+ func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
134
+
135
+
136
+
137
+ if pickerView.tag == 1{
138
+
139
+ koutsuusyudan.text = self.koutsuuList[row]
140
+
141
+ }
142
+
143
+ else{
144
+
145
+ kubun.text = self.kubunList[row]
146
+
147
+ }
148
+
149
+ }
150
+
151
+
152
+
153
+ func pickerView(pickerView: UIPickerView, rowHeightForComponent component: Int) -> CGFloat {
154
+
155
+ return 50
156
+
157
+ }
158
+
159
+
160
+
161
+ }
162
+
163
+ ```