質問編集履歴
1
最後にエラーが出ます
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,4 +1,8 @@
|
|
1
|
+
```ここに言語を入力
|
2
|
+
|
3
|
+
コード
|
4
|
+
|
1
|
-
### 前提・実現したいこと
|
5
|
+
```### 前提・実現したいこと
|
2
6
|
|
3
7
|
|
4
8
|
|
@@ -188,6 +192,158 @@
|
|
188
192
|
|
189
193
|
### 補足情報(FW/ツールのバージョンなど)
|
190
194
|
|
191
|
-
|
195
|
+
```ここに言語を入力
|
196
|
+
|
197
|
+
import UIKit
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
class ViewController: UIViewController,UITextFieldDelegate,UIPickerViewDelegate,UIPickerViewDataSource {
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
@IBOutlet weak var text_field_daieria: UITextField!
|
206
|
+
|
207
|
+
@IBOutlet weak var text_field_chueria: UITextField!
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
let chueria_dic:[String:[String]] = [
|
212
|
+
|
213
|
+
"北海道地方":["","北海道"],
|
214
|
+
|
215
|
+
"東北地方":["","青森県","秋田県","岩手県","宮城県","山形県","福島県"]]
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
let daieria_arr =
|
220
|
+
|
221
|
+
["","北海道地方","東北地方"]
|
222
|
+
|
223
|
+
let chueria_arr =
|
224
|
+
|
225
|
+
["","北海道","青森県","秋田県","岩手県","宮城県","山形県","福島県"]
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
let my_pickerView = UIPickerView()
|
234
|
+
|
235
|
+
var current_arr : [String] = []
|
236
|
+
|
237
|
+
var active_textfield : UITextField!
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
override func viewDidLoad() {
|
242
|
+
|
243
|
+
super.viewDidLoad()
|
244
|
+
|
245
|
+
// Do any additional setup after loading the view.
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
text_field_daieria.delegate = self
|
250
|
+
|
251
|
+
text_field_chueria.delegate = self
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
my_pickerView.delegate = self
|
256
|
+
|
257
|
+
my_pickerView.dataSource = self
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
text_field_daieria.inputView = my_pickerView
|
262
|
+
|
263
|
+
text_field_chueria.inputView = my_pickerView
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
}
|
268
|
+
|
269
|
+
//修正箇所
|
270
|
+
|
271
|
+
func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
|
272
|
+
|
273
|
+
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
|
278
|
+
|
279
|
+
switch textField{
|
280
|
+
|
281
|
+
case text_field_daieria:current_arr = daieria_arr
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
case text_field_chueria:
|
286
|
+
|
287
|
+
|
288
|
+
|
289
|
+
if let daieria = text_field_daieria.text,!daieria.isEmpty{
|
290
|
+
|
291
|
+
current_arr = chueria_dic[daieria]!
|
292
|
+
|
293
|
+
}else{
|
294
|
+
|
295
|
+
current_arr = chueria_arr
|
296
|
+
|
297
|
+
}
|
298
|
+
|
299
|
+
default:print("default")
|
300
|
+
|
301
|
+
}
|
302
|
+
|
303
|
+
my_pickerView.reloadAllComponents()
|
304
|
+
|
305
|
+
return true
|
306
|
+
|
307
|
+
}
|
308
|
+
|
309
|
+
|
310
|
+
|
311
|
+
override func didReceiveMemoryWarning() {
|
312
|
+
|
313
|
+
super.didReceiveMemoryWarning()
|
314
|
+
|
315
|
+
}
|
316
|
+
|
317
|
+
func numberOfComponents(in pickerView: UIPickerView) -> Int {
|
318
|
+
|
319
|
+
return 1
|
320
|
+
|
321
|
+
}
|
322
|
+
|
323
|
+
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
|
324
|
+
|
325
|
+
return current_arr.count
|
326
|
+
|
327
|
+
}
|
328
|
+
|
329
|
+
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
|
330
|
+
|
331
|
+
return current_arr[row]
|
332
|
+
|
333
|
+
}
|
334
|
+
|
335
|
+
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
|
336
|
+
|
337
|
+
**active_textfield.text = current_arr[row]**//ここで、Thread 1: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional valueとエラーが出ます。
|
338
|
+
|
339
|
+
|
340
|
+
|
341
|
+
}
|
342
|
+
|
343
|
+
|
344
|
+
|
345
|
+
}
|
346
|
+
|
347
|
+
```
|
192
348
|
|
193
349
|
ここにより詳細な情報を記載してください。
|