質問編集履歴

1

ソースコードを追記

2015/06/18 11:19

投稿

Satochan24
Satochan24

スコア113

test CHANGED
File without changes
test CHANGED
@@ -9,3 +9,307 @@
9
9
  参考にしたサイト
10
10
 
11
11
  http://andbyyou.com/ios-uipickerview%E3%82%92uiactionsheet%E5%86%85%E3%81%AB%E5%87%BA%E3%81%99%E3%81%8B%E3%81%A4picker%E3%82%92%E8%A4%87%E6%95%B0%E8%A8%AD%E5%AE%9A/
12
+
13
+
14
+
15
+
16
+
17
+ コードを貼ります。もともと、1画面内にピッカーを3つ配置していたのですが、試験的にActionシートでのピッカーを設置している内容です。
18
+
19
+ [CourseViewController.h]
20
+
21
+ ```lang-<#import <UIKit/UIKit.h>
22
+
23
+
24
+
25
+ @interface CourseViewController : UIViewController <UIPickerViewDelegate,UIPickerViewDataSource,UIActionSheetDelegate,UITextFieldDelegate>
26
+
27
+ {
28
+
29
+ // NSArray *bus_course; バスコースはサーバからの応答データを使用するため固定の値は使用しない。
30
+
31
+ NSArray *bus_ride_type;
32
+
33
+ NSArray *bus_measure_time_interval;
34
+
35
+ UIActionSheet *actionsheet;
36
+
37
+ }
38
+
39
+ @property (weak, nonatomic) IBOutlet UILabel *button_entry_label;
40
+
41
+ perty (nonatomic, strong) NSMutableArray *bus_course_mutable;
42
+
43
+ @property (nonatomic, strong) NSMutableArray *course_id_mutable;
44
+
45
+
46
+
47
+
48
+
49
+ - (IBAction)button_start:(UIButton *)sender;
50
+
51
+ - (IBAction)button_back:(UIButton *)sender;
52
+
53
+
54
+
55
+ @property (weak, nonatomic) IBOutlet UITextField *textField1;
56
+
57
+ @property (weak, nonatomic) IBOutlet UITextField *textField2;
58
+
59
+ @property (weak, nonatomic) IBOutlet UITextField *textField3;
60
+
61
+
62
+
63
+ @end>
64
+
65
+ コード
66
+
67
+ ```
68
+
69
+
70
+
71
+ [CourseViewController.m]
72
+
73
+ ```lang-<
74
+
75
+ #import "CourseViewController.h"
76
+
77
+ #import "GPSPositionViewController.h"
78
+
79
+
80
+
81
+ @interface CourseViewController ()
82
+
83
+
84
+
85
+ @property (weak, nonatomic) IBOutlet UIPickerView *picker;
86
+
87
+ @property (weak, nonatomic) IBOutlet UIPickerView *picker2;
88
+
89
+ @property (weak, nonatomic) IBOutlet UIPickerView *picker3;
90
+
91
+
92
+
93
+ @end
94
+
95
+
96
+
97
+ @implementation CourseViewController
98
+
99
+ {
100
+
101
+ // Action sheet test
102
+
103
+ UIPickerView *picker_1;
104
+
105
+ UIPickerView *picker_2;
106
+
107
+ UIPickerView *picker_3;
108
+
109
+
110
+
111
+ NSString *pic1_str;
112
+
113
+ NSString *pic2_str;
114
+
115
+ NSString *pic3_str;
116
+
117
+
118
+
119
+ }
120
+
121
+
122
+
123
+ // Action sheet test
124
+
125
+ @synthesize textField1;
126
+
127
+ @synthesize textField2;
128
+
129
+ @synthesize textField3;
130
+
131
+
132
+
133
+ - (void)viewDidLoad {
134
+
135
+ [super viewDidLoad];
136
+
137
+ // Do any additional setup after loading the view.
138
+
139
+
140
+
141
+
142
+
143
+ // パラメータ受け渡し
144
+
145
+ _textView_CsName.text = self.Cs_Name;
146
+
147
+ _textView_UserName.text = self.User_Name;
148
+
149
+ _Mode = self.Mode;
150
+
151
+
152
+
153
+ // 設定運行の処理
154
+
155
+ if ([_Mode isEqual: @"2"]) {
156
+
157
+ _button_entry_label.text = @"設定運行";
158
+
159
+ //_button_entry_label.textColor.redColor;
160
+
161
+ }
162
+
163
+
164
+
165
+
166
+
167
+ bus_ride_type = [NSArray arrayWithObjects:
168
+
169
+ @"登園",
170
+
171
+ @"降園", nil];
172
+
173
+ bus_measure_time_interval = [NSArray arrayWithObjects:
174
+
175
+ @"5",
176
+
177
+ @"10,nil];
178
+
179
+
180
+
181
+ _picker.delegate = self;
182
+
183
+ _picker2.delegate = self;
184
+
185
+ _picker3.delegate = self;
186
+
187
+ _picker.dataSource = self;
188
+
189
+ _picker2.dataSource = self;
190
+
191
+ _picker3.dataSource = self;
192
+
193
+
194
+
195
+ // Action sheet test
196
+
197
+ textField1.delegate = self;
198
+
199
+ textField2.delegate = self;
200
+
201
+ textField3.delegate = self;
202
+
203
+ textField1.tag = 1;
204
+
205
+ textField2.tag = 2;
206
+
207
+ textField3.tag = 3;
208
+
209
+
210
+
211
+ CGRect rect = [[UIScreen mainScreen] bounds];
212
+
213
+
214
+
215
+ picker_1 = [[UIPickerView alloc] init];
216
+
217
+ picker_1.frame = CGRectMake(0, rect.size.height, 320, 216);
218
+
219
+ picker_1.showsSelectionIndicator = YES;
220
+
221
+ picker_1.delegate = self;
222
+
223
+ picker_1.dataSource = self;
224
+
225
+ picker_1.tag = 1;
226
+
227
+ [self.view addSubview:picker_1];
228
+
229
+
230
+
231
+ picker_2 = [[UIPickerView alloc] init];
232
+
233
+ picker_2.frame = CGRectMake(0, rect.size.height, 320,216);
234
+
235
+ picker_2.showsSelectionIndicator = YES;
236
+
237
+ picker_2.delegate = self;
238
+
239
+ picker_2.dataSource = self;
240
+
241
+ picker_2.tag = 2;
242
+
243
+ [self.view addSubview:picker_2];
244
+
245
+
246
+
247
+ picker_3 = [[UIPickerView alloc] init];
248
+
249
+ picker_3.frame = CGRectMake(0, rect.size.height, 320,216);
250
+
251
+ picker_3.showsSelectionIndicator = YES;
252
+
253
+ picker_3.delegate = self;
254
+
255
+ picker_3.dataSource = self;
256
+
257
+ picker_3.tag = 2;
258
+
259
+ [self.view addSubview:picker_3];
260
+
261
+
262
+
263
+
264
+
265
+ // Action sheet test
266
+
267
+ - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
268
+
269
+ CGRect rect = [[UIScreen mainScreen] bounds];
270
+
271
+ if (textField.tag == 1) {
272
+
273
+ NSLog(@"1");
274
+
275
+ picker2.frame = CGRectMake(0, rect.size.height, 320, 216);
276
+
277
+ [self showPicker1]; //picker1を表示させるメソッドを実行
278
+
279
+ //キーボードは表示させない
280
+
281
+ return NO;
282
+
283
+ }
284
+
285
+ if (textField.tag == 2) {
286
+
287
+ NSLog(@"2");
288
+
289
+ picker1.frame = CGRectMake(0, rect.size.height, 320, 216);
290
+
291
+ [self showPicker2]; //picker2を表示させるメソッドを実行
292
+
293
+ //キーボードは表示させない
294
+
295
+ return NO;
296
+
297
+ }
298
+
299
+ return NO;
300
+
301
+ }
302
+
303
+
304
+
305
+
306
+
307
+ }
308
+
309
+
310
+
311
+ @end>
312
+
313
+ コード
314
+
315
+ ```