質問編集履歴
1
今までに試した方法を追記しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -221,3 +221,243 @@
|
|
221
221
|
|
222
222
|
|
223
223
|
```
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
<追記>
|
228
|
+
|
229
|
+
今までに試したtagで条件分岐させる方法
|
230
|
+
|
231
|
+
storyboard上でtextField1にtag1, textField2にtag2を入力。
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
```swift
|
236
|
+
|
237
|
+
import UIKit
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
class ContainerViewController: UITableViewController, UIPickerViewDelegate, UIPickerViewDataSource {
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
@IBOutlet weak var notificationTextField: UITextField!
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
let appDelegate = UIApplication.shared.delegate as! AppDelegate
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
var pickerView: UIPickerView = UIPickerView()
|
254
|
+
|
255
|
+
let list1 = ["", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31"]
|
256
|
+
|
257
|
+
let list2 = ["","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23"]
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
override func viewDidLoad() {
|
262
|
+
|
263
|
+
super.viewDidLoad()
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
pickerView.delegate = self
|
268
|
+
|
269
|
+
pickerView.dataSource = self
|
270
|
+
|
271
|
+
pickerView.showsSelectionIndicator = true
|
272
|
+
|
273
|
+
|
274
|
+
|
275
|
+
let toolbar = UIToolbar(frame: CGRectMake(0, 0, 0, 35))
|
276
|
+
|
277
|
+
let doneItem = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(ContainerViewController.done))
|
278
|
+
|
279
|
+
let cancelItem = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(ContainerViewController.cancel))
|
280
|
+
|
281
|
+
toolbar.setItems([cancelItem, doneItem], animated: true)
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
self.notificationTextField.inputView = pickerView
|
286
|
+
|
287
|
+
self.notificationTextField.inputAccessoryView = toolbar
|
288
|
+
|
289
|
+
|
290
|
+
|
291
|
+
tableView.isScrollEnabled = false
|
292
|
+
|
293
|
+
|
294
|
+
|
295
|
+
}
|
296
|
+
|
297
|
+
|
298
|
+
|
299
|
+
// MARK: - Table view data source
|
300
|
+
|
301
|
+
|
302
|
+
|
303
|
+
|
304
|
+
|
305
|
+
override func numberOfSections(in tableView: UITableView) -> Int {
|
306
|
+
|
307
|
+
// #warning Incomplete implementation, return the number of sections
|
308
|
+
|
309
|
+
return 1
|
310
|
+
|
311
|
+
}
|
312
|
+
|
313
|
+
|
314
|
+
|
315
|
+
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
316
|
+
|
317
|
+
|
318
|
+
|
319
|
+
return 3
|
320
|
+
|
321
|
+
}
|
322
|
+
|
323
|
+
|
324
|
+
|
325
|
+
//PickerView設定
|
326
|
+
|
327
|
+
|
328
|
+
|
329
|
+
func numberOfComponents(in pickerView: UIPickerView) -> Int {
|
330
|
+
|
331
|
+
|
332
|
+
|
333
|
+
return 1
|
334
|
+
|
335
|
+
|
336
|
+
|
337
|
+
}
|
338
|
+
|
339
|
+
|
340
|
+
|
341
|
+
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
|
342
|
+
|
343
|
+
|
344
|
+
|
345
|
+
if view.tag == 1{
|
346
|
+
|
347
|
+
return list1.count
|
348
|
+
|
349
|
+
}else{
|
350
|
+
|
351
|
+
return list2.count
|
352
|
+
|
353
|
+
}
|
354
|
+
|
355
|
+
|
356
|
+
|
357
|
+
}
|
358
|
+
|
359
|
+
|
360
|
+
|
361
|
+
|
362
|
+
|
363
|
+
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
|
364
|
+
|
365
|
+
|
366
|
+
|
367
|
+
if view.tag == 1{
|
368
|
+
|
369
|
+
return list1[row]
|
370
|
+
|
371
|
+
}else{
|
372
|
+
|
373
|
+
return list2[row]
|
374
|
+
|
375
|
+
}
|
376
|
+
|
377
|
+
|
378
|
+
|
379
|
+
}
|
380
|
+
|
381
|
+
|
382
|
+
|
383
|
+
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
|
384
|
+
|
385
|
+
|
386
|
+
|
387
|
+
if view.tag == 1{
|
388
|
+
|
389
|
+
self.notificationTextField.text = list1[row]
|
390
|
+
|
391
|
+
}else{
|
392
|
+
|
393
|
+
self.notificationTextField.text = list2[row]
|
394
|
+
|
395
|
+
}
|
396
|
+
|
397
|
+
|
398
|
+
|
399
|
+
}
|
400
|
+
|
401
|
+
|
402
|
+
|
403
|
+
@objc func cancel() {
|
404
|
+
|
405
|
+
if view.tag == 1{
|
406
|
+
|
407
|
+
self.notificationTextField.text = ""
|
408
|
+
|
409
|
+
self.notificationTextField.endEditing(true)
|
410
|
+
|
411
|
+
}
|
412
|
+
|
413
|
+
}
|
414
|
+
|
415
|
+
|
416
|
+
|
417
|
+
@objc func done() {
|
418
|
+
|
419
|
+
if view.tag == 1{
|
420
|
+
|
421
|
+
appDelegate.number1 = Int(notificationTextField.text!)
|
422
|
+
|
423
|
+
self.notificationTextField.endEditing(true)
|
424
|
+
|
425
|
+
}else{
|
426
|
+
|
427
|
+
appDelegate.number2 = Int(notificationTextField.text!)
|
428
|
+
|
429
|
+
self.notificationTextField.endEditing(true)
|
430
|
+
|
431
|
+
}
|
432
|
+
|
433
|
+
|
434
|
+
|
435
|
+
}
|
436
|
+
|
437
|
+
|
438
|
+
|
439
|
+
func CGRectMake(_ x: CGFloat, _ y: CGFloat, _ width: CGFloat, _ height: CGFloat) -> CGRect {
|
440
|
+
|
441
|
+
return CGRect(x: x, y: y, width: width, height: height)
|
442
|
+
|
443
|
+
}
|
444
|
+
|
445
|
+
|
446
|
+
|
447
|
+
override func didReceiveMemoryWarning() {
|
448
|
+
|
449
|
+
super.didReceiveMemoryWarning()
|
450
|
+
|
451
|
+
// Dispose of any resources that can be recreated.
|
452
|
+
|
453
|
+
}
|
454
|
+
|
455
|
+
|
456
|
+
|
457
|
+
}
|
458
|
+
|
459
|
+
|
460
|
+
|
461
|
+
```
|
462
|
+
|
463
|
+
これでそれぞれのTextFieldをnotificationTextFieldにOutlet接続したら条件分岐するかなと思ったらIBOutletは一つずつしか接続できなくてできませんでした。
|