質問編集履歴

1

バージョンの記載不足

2020/10/18 14:19

投稿

Gingami09
Gingami09

スコア1

test CHANGED
File without changes
test CHANGED
@@ -44,560 +44,560 @@
44
44
 
45
45
  ```
46
46
 
47
+ 画面A
48
+
49
+
50
+
51
+ import UIKit
52
+
53
+
54
+
55
+ class ViewController: UIViewController ,UITableViewDelegate,
56
+
57
+ UITableViewDataSource {
58
+
59
+
60
+
61
+
62
+
63
+ @IBOutlet weak var todolistTable: UITableView!
64
+
65
+
66
+
67
+
68
+
69
+
70
+
71
+
72
+
73
+
74
+
75
+ override func viewWillAppear(_ animated:Bool) {
76
+
77
+
78
+
79
+ super.viewWillAppear(animated)
80
+
81
+
82
+
83
+ if UserDefaults.standard.object(forKey: "todoList") != nil {
84
+
85
+ todoItem = UserDefaults.standard.object(forKey: "todoList") as! [String]
86
+
87
+
88
+
89
+ }
90
+
91
+
92
+
93
+ todolistTable.reloadData()
94
+
95
+ }
96
+
97
+
98
+
99
+
100
+
101
+
102
+
103
+ override func viewDidLoad() {
104
+
105
+ super.viewDidLoad()
106
+
107
+
108
+
109
+ }
110
+
111
+
112
+
113
+
114
+
115
+
116
+
117
+
118
+
119
+ func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
120
+
121
+ return todoItem.count
122
+
123
+ }
124
+
125
+
126
+
127
+
128
+
129
+ func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
130
+
131
+ let cellValue = UITableViewCell(style: UITableViewCell.CellStyle.default, reuseIdentifier: "cell")
132
+
133
+ cellValue .textLabel?.text = todoItem[indexPath.row]
134
+
135
+ return cellValue
136
+
137
+ }
138
+
139
+
140
+
141
+
142
+
143
+ // cellの編集許可
144
+
145
+ func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool
146
+
147
+ {
148
+
149
+ return true
150
+
151
+ }
152
+
153
+
154
+
155
+ // 追加:セルの削除機能
156
+
157
+ func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
158
+
159
+
160
+
161
+ if editingStyle == UITableViewCell.EditingStyle.delete {
162
+
163
+ todoItem.remove(at: indexPath.row)
164
+
165
+
166
+
167
+ tableView.deleteRows(at: [indexPath as IndexPath], with: .automatic)
168
+
169
+
170
+
171
+ UserDefaults.standard.set(todoItem , forKey: "todoList")
172
+
173
+
174
+
175
+ todolistTable.reloadData()
176
+
177
+
178
+
179
+
180
+
181
+ }
182
+
183
+
184
+
185
+
186
+
187
+
188
+
189
+
190
+
191
+
192
+
193
+ }
194
+
195
+
196
+
197
+
198
+
199
+
200
+
201
+ func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
202
+
203
+
204
+
205
+ // セルの選択を解除
206
+
207
+ tableView.deselectRow(at: indexPath, animated: true)
208
+
209
+
210
+
211
+ // 別の画面に遷移
212
+
213
+ performSegue(withIdentifier: "EditToDo", sender: nil)
214
+
215
+ }
216
+
217
+
218
+
219
+
220
+
221
+
222
+
223
+
224
+
225
+ override func viewDidAppear(_ animated: Bool) {
226
+
227
+ super.viewDidAppear(animated)
228
+
229
+ presentingViewController?.endAppearanceTransition()
230
+
231
+ }
232
+
233
+ override func viewWillDisappear(_ animated: Bool) {
234
+
235
+ super.viewWillDisappear(animated)
236
+
237
+ presentingViewController?.beginAppearanceTransition(true, animated: animated)
238
+
239
+ presentingViewController?.endAppearanceTransition()
240
+
241
+ }
242
+
243
+
244
+
245
+
246
+
247
+
248
+
249
+
250
+
251
+ }
252
+
253
+
254
+
255
+ ```
256
+
257
+
258
+
259
+ ```
260
+
261
+ 画面B
262
+
263
+ import UIKit
264
+
265
+
266
+
267
+ var todoItem = [String]()
268
+
269
+
270
+
271
+ class AddToDo: UIViewController {
272
+
273
+
274
+
275
+
276
+
277
+ @IBOutlet weak var itemText: UITextField!
278
+
279
+
280
+
281
+ @IBAction func addItem(_ sender: AnyObject) {
282
+
283
+
284
+
285
+
286
+
287
+
288
+
289
+ if itemText.text != "" {
290
+
291
+
292
+
293
+ todoItem.append(itemText.text!)
294
+
295
+ UserDefaults.standard.set(todoItem, forKey: "todoList")
296
+
297
+
298
+
299
+ }
300
+
301
+
302
+
303
+ dismiss(animated: true, completion: nil)
304
+
305
+
306
+
307
+
308
+
309
+ }
310
+
311
+
312
+
313
+
314
+
315
+
316
+
317
+
318
+
319
+
320
+
321
+ override func viewDidLoad() {
322
+
323
+ super.viewDidLoad()
324
+
325
+ }
326
+
327
+
328
+
329
+
330
+
331
+
332
+
333
+ @IBAction func tapScreen(_ sender: UITapGestureRecognizer) {self.view.endEditing(true)
334
+
335
+ }
336
+
337
+
338
+
339
+
340
+
341
+ @IBAction func ReturnButton(_ sender: Any) {
342
+
343
+
344
+
345
+ self.dismiss(animated: true, completion: nil)
346
+
347
+ }
348
+
349
+
350
+
351
+
352
+
353
+ override func viewWillAppear(_ animated: Bool) {
354
+
355
+ presentingViewController?.beginAppearanceTransition(false, animated: animated)
356
+
357
+ super.viewWillAppear(animated)
358
+
359
+ }
360
+
361
+ override func viewDidAppear(_ animated: Bool) {
362
+
363
+ super.viewDidAppear(animated)
364
+
365
+ presentingViewController?.endAppearanceTransition()
366
+
367
+ }
368
+
369
+ override func viewWillDisappear(_ animated: Bool) {
370
+
371
+ super.viewWillDisappear(animated)
372
+
373
+ presentingViewController?.beginAppearanceTransition(true, animated: animated)
374
+
375
+ presentingViewController?.endAppearanceTransition()
376
+
377
+ }
378
+
379
+
380
+
381
+ }
382
+
383
+ ```
384
+
385
+
386
+
387
+
388
+
389
+ ```
390
+
391
+ 画面C
392
+
393
+ import UIKit
394
+
395
+
396
+
397
+
398
+
399
+ class EditToDo: UIViewController {
400
+
401
+
402
+
403
+
404
+
405
+
406
+
407
+ @IBOutlet weak var EditingTextField : UITextField!
408
+
409
+
410
+
411
+
412
+
413
+ @IBAction func EditingButton(_ sender: AnyObject ){
414
+
415
+
416
+
417
+ if EditingTextField.text != "" {
418
+
419
+
420
+
421
+
422
+
423
+ // todoItem.append(EditingTextField.text!)
424
+
425
+ UserDefaults.standard.set(todoItem, forKey: "todoList")
426
+
427
+
428
+
429
+ }
430
+
431
+
432
+
433
+
434
+
435
+ dismiss(animated: true, completion: nil)
436
+
437
+
438
+
439
+ }
440
+
441
+
442
+
443
+
444
+
445
+
446
+
447
+ func Tableview(_ TableView : UITableView , cellForRowAt indexPath:IndexPath ) -> UITableViewCell {
448
+
449
+
450
+
451
+ let celling = UITableViewCell()
452
+
453
+ let edittextfield:Any = UITextField()
454
+
455
+ let rowNumber = indexPath.row
456
+
457
+
458
+
459
+ if rowNumber == todoItem.count {
460
+
461
+ todoItem = edittextfield as! [String]
462
+
463
+ }
464
+
465
+ return celling
466
+
467
+ }
468
+
469
+
470
+
471
+
472
+
473
+
474
+
475
+ func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool
476
+
477
+ {
478
+
479
+ return true
480
+
481
+ }
482
+
483
+
484
+
485
+
486
+
487
+ // 戻るボタン
488
+
489
+ @IBAction func EditReturnButton(_ sender: Any) {
490
+
491
+
492
+
493
+ self.dismiss(animated: true, completion: nil)
494
+
495
+
496
+
497
+ }
498
+
499
+
500
+
501
+ override func viewDidLoad() {
502
+
503
+ super.viewDidLoad()
504
+
505
+ }
506
+
507
+
508
+
509
+ // タップするとキーボードがなくなる
510
+
511
+
512
+
513
+ @IBAction func tapScreen(_ sender: UITapGestureRecognizer) {self.view.endEditing(true)
514
+
515
+ }
516
+
517
+
518
+
519
+ // 無限モーダル解消
520
+
521
+
522
+
523
+ override func viewWillAppear(_ animated: Bool) {
524
+
525
+ presentingViewController?.beginAppearanceTransition(false, animated: animated)
526
+
527
+ super.viewWillAppear(animated)
528
+
529
+ }
530
+
531
+ override func viewDidAppear(_ animated: Bool) {
532
+
533
+ super.viewDidAppear(animated)
534
+
535
+ presentingViewController?.endAppearanceTransition()
536
+
537
+ }
538
+
539
+ override func viewWillDisappear(_ animated: Bool) {
540
+
541
+ super.viewWillDisappear(animated)
542
+
543
+ presentingViewController?.beginAppearanceTransition(true, animated: animated)
544
+
545
+ presentingViewController?.endAppearanceTransition()
546
+
547
+ }
548
+
549
+
550
+
551
+
552
+
553
+
554
+
555
+
556
+
557
+
558
+
559
+
560
+
561
+ /*
562
+
563
+ // MARK: - Navigation
564
+
565
+
566
+
567
+ // In a storyboard-based application, you will often want to do a little preparation before navigation
568
+
569
+ override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
570
+
571
+ // Get the new view controller using segue.destination.
572
+
573
+ // Pass the selected object to the new view controller.
574
+
575
+ }
576
+
577
+ */
578
+
579
+
580
+
581
+ }
582
+
583
+
584
+
585
+ ```
586
+
587
+
588
+
589
+ ### 試したこと
590
+
591
+
592
+
593
+ ここに問題に対して試したことを記載してください。
594
+
595
+
596
+
597
+ ### 補足情報(FW/ツールのバージョンなど)
598
+
599
+
600
+
47
601
  swift5.3
48
602
 
49
- 画面A
50
-
51
-
52
-
53
- import UIKit
54
-
55
-
56
-
57
- class ViewController: UIViewController ,UITableViewDelegate,
58
-
59
- UITableViewDataSource {
60
-
61
-
62
-
63
-
64
-
65
- @IBOutlet weak var todolistTable: UITableView!
66
-
67
-
68
-
69
-
70
-
71
-
72
-
73
-
74
-
75
-
76
-
77
- override func viewWillAppear(_ animated:Bool) {
78
-
79
-
80
-
81
- super.viewWillAppear(animated)
82
-
83
-
84
-
85
- if UserDefaults.standard.object(forKey: "todoList") != nil {
86
-
87
- todoItem = UserDefaults.standard.object(forKey: "todoList") as! [String]
88
-
89
-
90
-
91
- }
92
-
93
-
94
-
95
- todolistTable.reloadData()
96
-
97
- }
98
-
99
-
100
-
101
-
102
-
103
-
104
-
105
- override func viewDidLoad() {
106
-
107
- super.viewDidLoad()
108
-
109
-
110
-
111
- }
112
-
113
-
114
-
115
-
116
-
117
-
118
-
119
-
120
-
121
- func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
122
-
123
- return todoItem.count
124
-
125
- }
126
-
127
-
128
-
129
-
130
-
131
- func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
132
-
133
- let cellValue = UITableViewCell(style: UITableViewCell.CellStyle.default, reuseIdentifier: "cell")
134
-
135
- cellValue .textLabel?.text = todoItem[indexPath.row]
136
-
137
- return cellValue
138
-
139
- }
140
-
141
-
142
-
143
-
144
-
145
- // cellの編集許可
146
-
147
- func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool
148
-
149
- {
150
-
151
- return true
152
-
153
- }
154
-
155
-
156
-
157
- // 追加:セルの削除機能
158
-
159
- func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
160
-
161
-
162
-
163
- if editingStyle == UITableViewCell.EditingStyle.delete {
164
-
165
- todoItem.remove(at: indexPath.row)
166
-
167
-
168
-
169
- tableView.deleteRows(at: [indexPath as IndexPath], with: .automatic)
170
-
171
-
172
-
173
- UserDefaults.standard.set(todoItem , forKey: "todoList")
174
-
175
-
176
-
177
- todolistTable.reloadData()
178
-
179
-
180
-
181
-
182
-
183
- }
184
-
185
-
186
-
187
-
188
-
189
-
190
-
191
-
192
-
193
-
194
-
195
- }
196
-
197
-
198
-
199
-
200
-
201
-
202
-
203
- func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
204
-
205
-
206
-
207
- // セルの選択を解除
208
-
209
- tableView.deselectRow(at: indexPath, animated: true)
210
-
211
-
212
-
213
- // 別の画面に遷移
214
-
215
- performSegue(withIdentifier: "EditToDo", sender: nil)
216
-
217
- }
218
-
219
-
220
-
221
-
222
-
223
-
224
-
225
-
226
-
227
- override func viewDidAppear(_ animated: Bool) {
228
-
229
- super.viewDidAppear(animated)
230
-
231
- presentingViewController?.endAppearanceTransition()
232
-
233
- }
234
-
235
- override func viewWillDisappear(_ animated: Bool) {
236
-
237
- super.viewWillDisappear(animated)
238
-
239
- presentingViewController?.beginAppearanceTransition(true, animated: animated)
240
-
241
- presentingViewController?.endAppearanceTransition()
242
-
243
- }
244
-
245
-
246
-
247
-
248
-
249
-
250
-
251
-
252
-
253
- }
254
-
255
-
256
-
257
- ```
258
-
259
-
260
-
261
- ```
262
-
263
- 画面B
264
-
265
- import UIKit
266
-
267
-
268
-
269
- var todoItem = [String]()
270
-
271
-
272
-
273
- class AddToDo: UIViewController {
274
-
275
-
276
-
277
-
278
-
279
- @IBOutlet weak var itemText: UITextField!
280
-
281
-
282
-
283
- @IBAction func addItem(_ sender: AnyObject) {
284
-
285
-
286
-
287
-
288
-
289
-
290
-
291
- if itemText.text != "" {
292
-
293
-
294
-
295
- todoItem.append(itemText.text!)
296
-
297
- UserDefaults.standard.set(todoItem, forKey: "todoList")
298
-
299
-
300
-
301
- }
302
-
303
-
304
-
305
- dismiss(animated: true, completion: nil)
306
-
307
-
308
-
309
-
310
-
311
- }
312
-
313
-
314
-
315
-
316
-
317
-
318
-
319
-
320
-
321
-
322
-
323
- override func viewDidLoad() {
324
-
325
- super.viewDidLoad()
326
-
327
- }
328
-
329
-
330
-
331
-
332
-
333
-
334
-
335
- @IBAction func tapScreen(_ sender: UITapGestureRecognizer) {self.view.endEditing(true)
336
-
337
- }
338
-
339
-
340
-
341
-
342
-
343
- @IBAction func ReturnButton(_ sender: Any) {
344
-
345
-
346
-
347
- self.dismiss(animated: true, completion: nil)
348
-
349
- }
350
-
351
-
352
-
353
-
354
-
355
- override func viewWillAppear(_ animated: Bool) {
356
-
357
- presentingViewController?.beginAppearanceTransition(false, animated: animated)
358
-
359
- super.viewWillAppear(animated)
360
-
361
- }
362
-
363
- override func viewDidAppear(_ animated: Bool) {
364
-
365
- super.viewDidAppear(animated)
366
-
367
- presentingViewController?.endAppearanceTransition()
368
-
369
- }
370
-
371
- override func viewWillDisappear(_ animated: Bool) {
372
-
373
- super.viewWillDisappear(animated)
374
-
375
- presentingViewController?.beginAppearanceTransition(true, animated: animated)
376
-
377
- presentingViewController?.endAppearanceTransition()
378
-
379
- }
380
-
381
-
382
-
383
- }
384
-
385
- ```
386
-
387
-
388
-
389
-
390
-
391
- ```
392
-
393
- 画面C
394
-
395
- import UIKit
396
-
397
-
398
-
399
-
400
-
401
- class EditToDo: UIViewController {
402
-
403
-
404
-
405
-
406
-
407
-
408
-
409
- @IBOutlet weak var EditingTextField : UITextField!
410
-
411
-
412
-
413
-
414
-
415
- @IBAction func EditingButton(_ sender: AnyObject ){
416
-
417
-
418
-
419
- if EditingTextField.text != "" {
420
-
421
-
422
-
423
-
424
-
425
- // todoItem.append(EditingTextField.text!)
426
-
427
- UserDefaults.standard.set(todoItem, forKey: "todoList")
428
-
429
-
430
-
431
- }
432
-
433
-
434
-
435
-
436
-
437
- dismiss(animated: true, completion: nil)
438
-
439
-
440
-
441
- }
442
-
443
-
444
-
445
-
446
-
447
-
448
-
449
- func Tableview(_ TableView : UITableView , cellForRowAt indexPath:IndexPath ) -> UITableViewCell {
450
-
451
-
452
-
453
- let celling = UITableViewCell()
454
-
455
- let edittextfield:Any = UITextField()
456
-
457
- let rowNumber = indexPath.row
458
-
459
-
460
-
461
- if rowNumber == todoItem.count {
462
-
463
- todoItem = edittextfield as! [String]
464
-
465
- }
466
-
467
- return celling
468
-
469
- }
470
-
471
-
472
-
473
-
474
-
475
-
476
-
477
- func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool
478
-
479
- {
480
-
481
- return true
482
-
483
- }
484
-
485
-
486
-
487
-
488
-
489
- // 戻るボタン
490
-
491
- @IBAction func EditReturnButton(_ sender: Any) {
492
-
493
-
494
-
495
- self.dismiss(animated: true, completion: nil)
496
-
497
-
498
-
499
- }
500
-
501
-
502
-
503
- override func viewDidLoad() {
504
-
505
- super.viewDidLoad()
506
-
507
- }
508
-
509
-
510
-
511
- // タップするとキーボードがなくなる
512
-
513
-
514
-
515
- @IBAction func tapScreen(_ sender: UITapGestureRecognizer) {self.view.endEditing(true)
516
-
517
- }
518
-
519
-
520
-
521
- // 無限モーダル解消
522
-
523
-
524
-
525
- override func viewWillAppear(_ animated: Bool) {
526
-
527
- presentingViewController?.beginAppearanceTransition(false, animated: animated)
528
-
529
- super.viewWillAppear(animated)
530
-
531
- }
532
-
533
- override func viewDidAppear(_ animated: Bool) {
534
-
535
- super.viewDidAppear(animated)
536
-
537
- presentingViewController?.endAppearanceTransition()
538
-
539
- }
540
-
541
- override func viewWillDisappear(_ animated: Bool) {
542
-
543
- super.viewWillDisappear(animated)
544
-
545
- presentingViewController?.beginAppearanceTransition(true, animated: animated)
546
-
547
- presentingViewController?.endAppearanceTransition()
548
-
549
- }
550
-
551
-
552
-
553
-
554
-
555
-
556
-
557
-
558
-
559
-
560
-
561
-
562
-
563
- /*
564
-
565
- // MARK: - Navigation
566
-
567
-
568
-
569
- // In a storyboard-based application, you will often want to do a little preparation before navigation
570
-
571
- override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
572
-
573
- // Get the new view controller using segue.destination.
574
-
575
- // Pass the selected object to the new view controller.
576
-
577
- }
578
-
579
- */
603
+ Xcode12.0
580
-
581
-
582
-
583
- }
584
-
585
-
586
-
587
- ```
588
-
589
-
590
-
591
- ### 試したこと
592
-
593
-
594
-
595
- ここに問題に対して試したことを記載してください。
596
-
597
-
598
-
599
- ### 補足情報(FW/ツールのバージョンなど)
600
-
601
-
602
-
603
- ここにより詳細な情報を記載してください。