質問編集履歴
2
コードの大幅な変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
```swift
|
2
2
|
|
3
|
+
//ViewController.swift
|
4
|
+
|
3
5
|
import UIKit
|
4
6
|
|
5
7
|
|
@@ -12,6 +14,14 @@
|
|
12
14
|
|
13
15
|
|
14
16
|
|
17
|
+
//構造体
|
18
|
+
|
19
|
+
let initialItems: [String] = []
|
20
|
+
|
21
|
+
var kei: [Cell] = Array()
|
22
|
+
|
23
|
+
|
24
|
+
|
15
25
|
var item: [String] = []
|
16
26
|
|
17
27
|
var cnt = 0
|
@@ -56,42 +66,6 @@
|
|
56
66
|
|
57
67
|
|
58
68
|
|
59
|
-
//ボタンについて
|
60
|
-
|
61
|
-
let button = UIButton()
|
62
|
-
|
63
|
-
button.backgroundColor = UIColor.lightGray
|
64
|
-
|
65
|
-
button.setTitle("➕", for: .normal)
|
66
|
-
|
67
|
-
button.tintColor = UIColor.red
|
68
|
-
|
69
|
-
cell.contentView.addSubview(button)
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
button.translatesAutoresizingMaskIntoConstraints = false
|
74
|
-
|
75
|
-
cell.contentView.rightAnchor.constraint(equalTo: button.rightAnchor, constant: 8).isActive = true
|
76
|
-
|
77
|
-
// 中央にする
|
78
|
-
|
79
|
-
//button.centerYAnchor.constraint(equalTo: cell.centerYAnchor).isActive = true
|
80
|
-
|
81
|
-
//丸みに対して
|
82
|
-
|
83
|
-
button.layer.cornerRadius = 10
|
84
|
-
|
85
|
-
button.layer.masksToBounds = true
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
cell.contentView.heightAnchor.constraint(equalTo: button.heightAnchor, multiplier: 1).isActive = true
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
69
|
var labels: [UILabel] = []
|
96
70
|
|
97
71
|
//labelについて
|
@@ -388,6 +362,106 @@
|
|
388
362
|
|
389
363
|
}
|
390
364
|
|
365
|
+
|
366
|
+
|
367
|
+
|
368
|
+
|
369
|
+
//注意
|
370
|
+
|
371
|
+
|
372
|
+
|
373
|
+
func alert(){
|
374
|
+
|
375
|
+
// テキストフィールド付きアラート表示
|
376
|
+
|
377
|
+
|
378
|
+
|
379
|
+
let alert = UIAlertController(title: "タイトル", message: "メッセージ", preferredStyle: .alert)
|
380
|
+
|
381
|
+
|
382
|
+
|
383
|
+
// OKボタンの設定
|
384
|
+
|
385
|
+
let okAction = UIAlertAction(title: "OK", style: .default, handler: {
|
386
|
+
|
387
|
+
(action:UIAlertAction!) -> Void in
|
388
|
+
|
389
|
+
|
390
|
+
|
391
|
+
// OKを押した時入力されていたテキストを表示
|
392
|
+
|
393
|
+
if let textFields = alert.textFields {
|
394
|
+
|
395
|
+
|
396
|
+
|
397
|
+
// アラートに含まれるすべてのテキストフィールドを調べる
|
398
|
+
|
399
|
+
for textField in textFields {
|
400
|
+
|
401
|
+
self.item.insert(textField.text!, at: 0)
|
402
|
+
|
403
|
+
self.itemTotal[self.cnt] = self.item
|
404
|
+
|
405
|
+
|
406
|
+
|
407
|
+
if self.item.count % 5 == 0, self.itemTotal[0].count > 1 {
|
408
|
+
|
409
|
+
self.cnt += 1
|
410
|
+
|
411
|
+
self.itemTotal.append([])
|
412
|
+
|
413
|
+
self.item = []
|
414
|
+
|
415
|
+
print(textField.text!)
|
416
|
+
|
417
|
+
//self.Gesture()
|
418
|
+
|
419
|
+
//self.doubleclic()
|
420
|
+
|
421
|
+
}
|
422
|
+
|
423
|
+
self.mytableView.reloadData()
|
424
|
+
|
425
|
+
}
|
426
|
+
|
427
|
+
}
|
428
|
+
|
429
|
+
})
|
430
|
+
|
431
|
+
alert.addAction(okAction)
|
432
|
+
|
433
|
+
|
434
|
+
|
435
|
+
// キャンセルボタンの設定
|
436
|
+
|
437
|
+
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
|
438
|
+
|
439
|
+
alert.addAction(cancelAction)
|
440
|
+
|
441
|
+
|
442
|
+
|
443
|
+
// テキストフィールドを追加
|
444
|
+
|
445
|
+
alert.addTextField(configurationHandler: {(textField: UITextField!) -> Void in
|
446
|
+
|
447
|
+
textField.placeholder = "テキスト"
|
448
|
+
|
449
|
+
})
|
450
|
+
|
451
|
+
|
452
|
+
|
453
|
+
alert.view.setNeedsLayout() // シミュレータの種類によっては、これがないと警告が発生
|
454
|
+
|
455
|
+
|
456
|
+
|
457
|
+
// アラートを画面に表示
|
458
|
+
|
459
|
+
self.present(alert, animated: true, completion: nil)
|
460
|
+
|
461
|
+
|
462
|
+
|
463
|
+
}
|
464
|
+
|
391
465
|
|
392
466
|
|
393
467
|
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
|
@@ -402,12 +476,24 @@
|
|
402
476
|
|
403
477
|
super.viewDidLoad()
|
404
478
|
|
479
|
+
|
480
|
+
|
405
481
|
mytableView.delegate = self
|
406
482
|
|
407
483
|
mytableView.dataSource = self
|
408
484
|
|
409
485
|
mytableView.estimatedRowHeight = 60
|
410
486
|
|
487
|
+
//mytableView.backgroundColor = UIColor(red: 0.0, green: 0.8, blue: 1.0, alpha: 0.1)
|
488
|
+
|
489
|
+
|
490
|
+
|
491
|
+
for item in initialItems {
|
492
|
+
|
493
|
+
kei.append(Cell(item: item, cellcolor: false))
|
494
|
+
|
495
|
+
}
|
496
|
+
|
411
497
|
}
|
412
498
|
|
413
499
|
|
@@ -430,8 +516,6 @@
|
|
430
516
|
|
431
517
|
}
|
432
518
|
|
433
|
-
|
434
|
-
|
435
519
|
```
|
436
520
|
|
437
521
|
|
@@ -454,96 +538,60 @@
|
|
454
538
|
|
455
539
|
```swift
|
456
540
|
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
self.mytableView.reloadData()
|
508
|
-
|
509
|
-
}
|
510
|
-
|
511
|
-
}
|
512
|
-
|
513
|
-
})
|
514
|
-
|
515
|
-
alert.addAction(okAction)
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
// キャンセルボタンの設定
|
520
|
-
|
521
|
-
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
|
522
|
-
|
523
|
-
alert.addAction(cancelAction)
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
// テキストフィールドを追加
|
528
|
-
|
529
|
-
alert.addTextField(configurationHandler: {(textField: UITextField!) -> Void in
|
530
|
-
|
531
|
-
textField.placeholder = "テキスト"
|
532
|
-
|
533
|
-
})
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
alert.view.setNeedsLayout() // シミュレータの種類によっては、これがないと警告が発生
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
// アラートを画面に表示
|
542
|
-
|
543
|
-
self.present(alert, animated: true, completion: nil)
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
}
|
541
|
+
//cell.swift
|
542
|
+
|
543
|
+
struct Cell {
|
544
|
+
|
545
|
+
//var category: String
|
546
|
+
|
547
|
+
//var name: String
|
548
|
+
|
549
|
+
var title: String
|
550
|
+
|
551
|
+
var item: String
|
552
|
+
|
553
|
+
var cellcolor: Bool
|
554
|
+
|
555
|
+
var cnt = 0
|
556
|
+
|
557
|
+
|
558
|
+
|
559
|
+
init(item: String,cellcolor: Bool) {
|
560
|
+
|
561
|
+
self.init(title: item,item: item,cellcolor: cellcolor)
|
562
|
+
|
563
|
+
self.item = item;
|
564
|
+
|
565
|
+
self.cellcolor = cellcolor;
|
566
|
+
|
567
|
+
//self.itemTotal = item;
|
568
|
+
|
569
|
+
}
|
570
|
+
|
571
|
+
|
572
|
+
|
573
|
+
init(title: String,item: String,cellcolor: Bool) {
|
574
|
+
|
575
|
+
self.title = title;
|
576
|
+
|
577
|
+
self.item = item;
|
578
|
+
|
579
|
+
self.cellcolor = cellcolor;
|
580
|
+
|
581
|
+
//self.itemTotal = item;
|
582
|
+
|
583
|
+
}
|
584
|
+
|
585
|
+
|
586
|
+
|
587
|
+
}
|
588
|
+
|
589
|
+
|
548
590
|
|
549
591
|
```
|
592
|
+
|
593
|
+
|
594
|
+
|
595
|
+
最新のコードです。
|
596
|
+
|
597
|
+
構造体でtitleセルとdetailセルをグループ化しようとしています。
|
1
説明の追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -449,3 +449,101 @@
|
|
449
449
|
最初に題名となるセルを追加しようとコードを加えたのですが実行時にはエラーは起きないのですが実際にアラートを呼び出し**OK**とタップすると落ちてしまいます。
|
450
450
|
|
451
451
|
エラーはsignal SIGABRTによるものです。
|
452
|
+
|
453
|
+
|
454
|
+
|
455
|
+
```swift
|
456
|
+
|
457
|
+
func alert(){
|
458
|
+
|
459
|
+
// テキストフィールド付きアラート表示
|
460
|
+
|
461
|
+
|
462
|
+
|
463
|
+
let alert = UIAlertController(title: "タイトル", message: "メッセージ", preferredStyle: .alert)
|
464
|
+
|
465
|
+
|
466
|
+
|
467
|
+
// OKボタンの設定
|
468
|
+
|
469
|
+
let okAction = UIAlertAction(title: "OK", style: .default, handler: {
|
470
|
+
|
471
|
+
(action:UIAlertAction!) -> Void in
|
472
|
+
|
473
|
+
|
474
|
+
|
475
|
+
// OKを押した時入力されていたテキストを表示
|
476
|
+
|
477
|
+
if let textFields = alert.textFields {
|
478
|
+
|
479
|
+
|
480
|
+
|
481
|
+
// アラートに含まれるすべてのテキストフィールドを調べる
|
482
|
+
|
483
|
+
for textField in textFields {
|
484
|
+
|
485
|
+
self.item.insert(textField.text!, at: 0)
|
486
|
+
|
487
|
+
self.itemTotal[self.cnt] = self.item
|
488
|
+
|
489
|
+
|
490
|
+
|
491
|
+
if self.item.count % 5 == 0, self.itemTotal[0].count > 1 {
|
492
|
+
|
493
|
+
self.cnt += 1
|
494
|
+
|
495
|
+
self.itemTotal.append([])
|
496
|
+
|
497
|
+
self.item = []
|
498
|
+
|
499
|
+
print(textField.text!)
|
500
|
+
|
501
|
+
//self.Gesture()
|
502
|
+
|
503
|
+
//self.doubleclic()
|
504
|
+
|
505
|
+
}
|
506
|
+
|
507
|
+
self.mytableView.reloadData()
|
508
|
+
|
509
|
+
}
|
510
|
+
|
511
|
+
}
|
512
|
+
|
513
|
+
})
|
514
|
+
|
515
|
+
alert.addAction(okAction)
|
516
|
+
|
517
|
+
|
518
|
+
|
519
|
+
// キャンセルボタンの設定
|
520
|
+
|
521
|
+
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
|
522
|
+
|
523
|
+
alert.addAction(cancelAction)
|
524
|
+
|
525
|
+
|
526
|
+
|
527
|
+
// テキストフィールドを追加
|
528
|
+
|
529
|
+
alert.addTextField(configurationHandler: {(textField: UITextField!) -> Void in
|
530
|
+
|
531
|
+
textField.placeholder = "テキスト"
|
532
|
+
|
533
|
+
})
|
534
|
+
|
535
|
+
|
536
|
+
|
537
|
+
alert.view.setNeedsLayout() // シミュレータの種類によっては、これがないと警告が発生
|
538
|
+
|
539
|
+
|
540
|
+
|
541
|
+
// アラートを画面に表示
|
542
|
+
|
543
|
+
self.present(alert, animated: true, completion: nil)
|
544
|
+
|
545
|
+
|
546
|
+
|
547
|
+
}
|
548
|
+
|
549
|
+
```
|